Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Python
  4. [Help]H.W issues

[Help]H.W issues

Scheduled Pinned Locked Moved Python
linqsecurityfunctionalhelp
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    iI i i 2021
    wrote on last edited by
    #1

    import re

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Part 1

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

    def creation_of_dictionary(message):
    print(f"In creation_of_dictionary: message= {message}")
    m = {}
    l = []
    z4 = {}
    mc = ['r', 'o', 't', 'e']
    for i in message:
    if i.isalpha():
    b = i.lower()
    l.append(b)
    print(f"creation_of_dictionary:l={l}")

    for g in range(len(l)):
        f = l.count(l\[g\])
        m\[l\[g\]\] = f
        tuples = m.items()
        tuples = sorted(tuples, key=lambda tuples: tuples\[1\])
    print(f"tuples = {tuples}")
    
    for e in \[-4, -3, -2, -1\]:
        z4\[mc\[m\]\] = tuples\[e\]\[0\]
        z4\[tuples\[e\]\[0\]\] = mc\[e\]
    
    print(z4)
    return (z4)
    

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Part 2

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

    def decode(message, dict):
    lists = []
    for m in message:
    l = m.lower()
    lists.append(l)
    for s in range(len(lists)):
    if lists[s] in dict.keys():
    lists[s] = dict[lists[s]]
    b = ''.join(lists)
    return b

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Part 3

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

    def txt_decode(path):
    lines = []
    newdic = {}
    m = open(path, 'r')
    q = m.readlines()
    m.close()
    for i in range(len(q)):
    q[i] = q[i].rstrip()
    newdic = creation_of_dictionary(''.join(q))
    for t in range(len(q)):
    lines.append(decode(q[t], newdic))
    f = open(path, 'a')
    f2 = open("result.txt", 'w')
    f.write("\n The encryption for the above text is:\n")
    for n in range(len(lines)):
    f.write(lines[n])
    f2.write(lines[n])
    f.write('\n')
    f2.write('\n')

    L 1 Reply Last reply
    0
    • I iI i i 2021

      import re

      ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

      Part 1

      ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

      def creation_of_dictionary(message):
      print(f"In creation_of_dictionary: message= {message}")
      m = {}
      l = []
      z4 = {}
      mc = ['r', 'o', 't', 'e']
      for i in message:
      if i.isalpha():
      b = i.lower()
      l.append(b)
      print(f"creation_of_dictionary:l={l}")

      for g in range(len(l)):
          f = l.count(l\[g\])
          m\[l\[g\]\] = f
          tuples = m.items()
          tuples = sorted(tuples, key=lambda tuples: tuples\[1\])
      print(f"tuples = {tuples}")
      
      for e in \[-4, -3, -2, -1\]:
          z4\[mc\[m\]\] = tuples\[e\]\[0\]
          z4\[tuples\[e\]\[0\]\] = mc\[e\]
      
      print(z4)
      return (z4)
      

      ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

      Part 2

      ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

      def decode(message, dict):
      lists = []
      for m in message:
      l = m.lower()
      lists.append(l)
      for s in range(len(lists)):
      if lists[s] in dict.keys():
      lists[s] = dict[lists[s]]
      b = ''.join(lists)
      return b

      ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

      Part 3

      ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

      def txt_decode(path):
      lines = []
      newdic = {}
      m = open(path, 'r')
      q = m.readlines()
      m.close()
      for i in range(len(q)):
      q[i] = q[i].rstrip()
      newdic = creation_of_dictionary(''.join(q))
      for t in range(len(q)):
      lines.append(decode(q[t], newdic))
      f = open(path, 'a')
      f2 = open("result.txt", 'w')
      f.write("\n The encryption for the above text is:\n")
      for n in range(len(lines)):
      f.write(lines[n])
      f2.write(lines[n])
      f.write('\n')
      f2.write('\n')

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      אנטון מוטרוק 2021 wrote:

      errors such as message.txt file doesnt exist etc

      If you get errors then you need to provide the exact text, and explain which line they occurred on. Remember we have never seen this code before, have no idea what is is supposed to do or what data it is processing. Also, instead of trying to write the entire application in one go, stop and look at the task(s) you have been set. Go by the numbers in your questions: write the code just for that step, and test it until it works successfully. Only then should you move on to the next step, and so on, until you complete the entire application.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups