cen.py (881B)
1 # Python implementation of the Caesar cipher (encryption script) # 2 # MCD 2020 GPLv3 # 3 import sys 4 5 alphabet_doubled = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] 6 7 def encrypt(): 8 en_text = "" 9 for character in plain_text: 10 count = 0 11 for alph_char in alphabet_doubled[:26]: 12 count = count + 1 13 if alph_char == character: 14 en_text = en_text+ alphabet_doubled[count+value] 15 break 16 elif count >= 26: 17 en_text = en_text + character 18 19 print(en_text) 20 21 if( len(sys.argv) > 2 ): 22 value = int(sys.argv[1]) - 1 23 plain_text = sys.argv[2].lower() 24 try: 25 encrypt() 26 except: 27 print("\nTerminated.") 28 else: 29 print("Usage: python cen.py [VALUE] [PLAIN_TEXT]") 30 print("Example: python cen.py 4 \'hello\'") 31 exit(0)