Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.51 KB | None | 0 0
  1. # custom digital encoder/decoder
  2.  
  3. import time as t
  4.  
  5. text_decode = 'Enter string to Decode...'
  6. text_encode = 'Type string to Encode...'
  7.  
  8. numbers = { "a": "10110100",
  9.             "b": "00000001",
  10.             "c": "00000010",
  11.             "d": "00000011",
  12.             "e": "01011010",
  13.             "f": "00000100",
  14.             "g": "00000101",
  15.             "h": "00000110",
  16.             "i": "00000111",
  17.             "j": "00001000",
  18.             "k": "00001001",
  19.             "l": "00001010",
  20.             "m": "00001011",
  21.             "n": "00001100",
  22.             "o": "00001101",
  23.             "p": "00001110",
  24.             "q": "00001111",
  25.             "r": "00010000",
  26.             "s": "00010001",
  27.             "t": "00010010",
  28.             "u": "00010011",
  29.             "v": "00010100",
  30.             "w": "00010101",
  31.             "x": "00010110",
  32.             "y": "00010111",
  33.             "z": "00011000",
  34.             "A": "00011001",
  35.             "B": "00011010",
  36.             "C": "00011011",
  37.             "D": "00011100",
  38.             "E": "00011101",
  39.             "F": "00011110",
  40.             "G": "00011111",
  41.             "H": "00100000",
  42.             "I": "00100001",
  43.             "J": "00100010",
  44.             "K": "00100011",
  45.             "L": "00100100",
  46.             "M": "00100101",
  47.             "N": "00100110",
  48.             "O": "00100111",
  49.             "P": "00101000",
  50.             "Q": "00101001",
  51.             "R": "00101010",
  52.             "S": "00101011",
  53.             "T": "00101100",
  54.             "U": "00101101",
  55.             "V": "00101110",
  56.             "W": "00101111",
  57.             "X": "100010011",
  58.             "Y": "00110000",
  59.             "Z": "00110001",
  60.             "1": "00110010",
  61.             "2": "00110011",
  62.             "3": "00110100",
  63.             "4": "00110101",
  64.             "5": "00110110",
  65.             "6": "00110111",
  66.             "7": "00111000",
  67.             "8": "00111001",
  68.             "9": "00111010",
  69.             "0": "00111011",
  70.             " ": "10000100" }
  71.  
  72. print("Please wait until all resources are loaded... ")
  73.  
  74. def root():
  75.     answer = input("Decode or encode? >>> ")
  76.     if answer.lower() == "decode":
  77.         print(text_decode)
  78.         encode_s = input(" >> ")
  79.        
  80.         print(' '.join(list(numbers.keys())[list(numbers.values()).index(c)] for c in encode_s.split()))
  81.         root()
  82.  
  83.     elif answer.lower() == "encode":
  84.         print(text_encode)
  85.         decode_s = input(" >> ")
  86.        
  87.         print(' '.join(numbers[c] for c in decode_s))
  88.         root()
  89. root()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement