Python Forum
Monoalphabetic cipher
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Monoalphabetic cipher
#1
Hello!
I wrote this code:
keys={'a':'z','b':'y','c':'x','d':'w','e':'v','f':'u','g':'t','h':'s','i':'r','j':'q','k':'p','l':'o','m':'n'}
reverse_keys={}
for key,value in keys.items():
    reverse_keys[value]=key
def encrypt(text):
    text=str(text)
    encrypting=[]
    for l in text:
        encrypting.append(keys.get(l,l))
    print(''.join(encrypting))
def decipher(text):
    text=str(text)
    decrypted=[]
    for l in text:
        decrypted.append(reverse_keys.get(l,l))
    print(''.join(decrypted))
print(encrypt("hej"))
print(decipher("svq"))
But now I want to create a function encrypt(text,keys) for example encrypt(hej,"zyxwvutsrqponmlkjihgfedcba"). I want the user to define the key himself.
Reply


Messages In This Thread
Monoalphabetic cipher - by pawlo392 - Apr-01-2019, 08:33 PM
RE: Monoalphabetic cipher - by ichabod801 - Apr-01-2019, 08:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Cipher Caesar Azilkhan 1 2,189 Nov-21-2019, 03:40 PM
Last Post: ichabod801
  Caesar cipher Drone4four 19 10,940 Nov-11-2018, 04:07 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020