Friday, October 06, 2017

Monoalphabetic Substitution Cipher in Python

import random

plain_text = "devharsh_T @ $01.2"
cipher_text = ''
decipher_text = ''

alphabets = [chr(a) for a in range(0,127)]
mappings = [chr(a) for a in range(0,127)]

random.shuffle(mappings)

print(alphabets)
print(mappings)

for i in range(len(plain_text)):
  for j in range(127):
    if(plain_text[i] == alphabets[j]):
      cipher_text += mappings[j]
 
print(plain_text)
print(cipher_text)

for i in range(len(cipher_text)):
  for j in range(127):
    if(cipher_text[i] == mappings[j]):
      decipher_text += alphabets[j]
     
print(decipher_text)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.