Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. def enc(sys):
  2.    
  3.     A1 = sys // 1000
  4.     A2 = (sys // 100) % 10
  5.     A3 = (sys // 10) % 10
  6.     A4 = (sys // 1) % 10
  7.  
  8.     A1 += 7
  9.     A1 = A1 % 10
  10.  
  11.     A2 += 7
  12.     A2 = A2 % 10
  13.  
  14.     A3 += 7
  15.     A3 = A3 % 10
  16.    
  17.     A4 += 7
  18.     A4 = A4 % 10
  19.    
  20.     res = 0
  21.     res += A3 * 1000
  22.     res += A4 * 100
  23.     res += A1 * 10
  24.     res += A2
  25.     #str(A3)+str(A4)+str(A1)+str(A2)
  26.     res = print(A3,A4,A1,A2)
  27.     return res #if i make it become int , 0 will not shown
  28. def dec(sys):
  29.     A1 = sys // 1000
  30.     A2 = (sys // 100) % 10
  31.     A3 = (sys // 10) % 10
  32.     A4 = (sys // 1) % 10
  33.  
  34.     A1 = A1 % 10
  35.     A1 -= 7
  36.  
  37.     A2 = A2 % 10
  38.     A2 -= 7
  39.  
  40.     A3 = A3 % 10
  41.     A3 -= 7
  42.    
  43.     A4 = A4 % 10
  44.     A4 -= 7
  45.  
  46.     #checked the value
  47.     if(A1<0):
  48.         A1 += 10
  49.     if(A2<0):
  50.         A2 += 10
  51.     if(A3<0):
  52.         A3 += 10
  53.     if(A4<0):
  54.         A4 += 10
  55.        
  56.     res = 0
  57.     res += A3 * 1000
  58.     res += A4 * 100
  59.     res += A1 * 10
  60.     res += A2
  61.     res = print(A3,A4,A1,A2)
  62.     return res
  63. #print(enc(1234))
  64. #print(dec(enc(1234)))
  65.  
  66.  
  67. def main():
  68.     sys = 1
  69.     while sys!=3:
  70.         print("=======MENU=======")
  71.         print("1. Encrypt message")
  72.         print("2. Decrypt message")
  73.         print("3. Quit Program")
  74.         ch = eval(input("please choose number 1, 2 or 3 : "))
  75.         sys = eval(input("input the number in 4 digit : "))
  76.  
  77.         if ch == 1 :
  78.             enc(sys)
  79.         elif ch== 2:
  80.             dec(sys)
  81.         elif ch == 3:
  82.              exit
  83.         else :
  84.             print("number is not valid")
  85. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement