Advertisement
NightRaven97

Shift Cipher

Apr 26th, 2015
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. #Shift cipher from keys 0 to 25
  2. #Decipher program => http://pastebin.com/SaU5edKQ
  3. #Display all possible deciphers => http://pastebin.com/Zn32AcxA
  4. import random
  5. print "CIPHER PROGRAM"
  6. message=raw_input('Enter the message to be ciphered:')
  7. message=message.lower()
  8. key=raw_input('Enter a number:')
  9. key=int(key)
  10. flag=0
  11. if key>26:
  12.     key=int(key)%26
  13. elif key==0:
  14.     key=random.randrange(1,26)
  15.     flag=1
  16. num_equivalent={
  17. ' ':-int(key),'a':1,'b':2,'c':3,'d':4,'e':5,'f':6,'g':7,'h':8,'i':9,'j':10,'k':11,'l':12,'m':13,'n':14,'o':15,'p':16,'q':17,'r':18,'s':19,'t':20,'u':21,'v':22,'w':23,'x':24,'y':25,'z':26,
  18. }
  19. alpha_equivalent={
  20. 0:' ',1:'a',2:'b',3:'c',4:'d',5:'e',6:'f',7:'g',8:'h',9:'i',10:'j',11:'k',12:'l',13:'m',14:'n',15:'o',16:'p',17:'q',18:'r',19:'s',20:'t',21:'u',22:'v',23:'w',24:'x',25:'y',26:'z',
  21. }
  22. print "Ciphered message:"
  23. for letter in message:
  24.     x=num_equivalent[letter]+key
  25.     if x>26:
  26.         x=x%26
  27.     y=alpha_equivalent[x]
  28.     print y.upper(),
  29. if flag==1:
  30.     print "Your secret key is %s"%(key)
  31. raw_input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement