fork(2) download
  1. #!/usr/bin/env python
  2. import sys
  3.  
  4. alphaL = "abcdefghijklnmopqrstuvqxyz"
  5. alphaU = "ABCDEFGHIJKLMNOPQRSTUVQXYZ"
  6. num = "0123456789"
  7. keychars = num+alphaL+alphaU
  8.  
  9.  
  10. key = "T0pS3cre7key"
  11. if not key.isalnum():
  12. print "Your key is invalid, it may only be alphanumeric characters"
  13. sys.exit()
  14.  
  15. plaintext = "???"
  16.  
  17. ciphertext = ""
  18. decipher = ""
  19. for i in range(len(plaintext)):
  20. rotate_amount = keychars.index(key[i%len(key)])
  21. if plaintext[i] in alphaL:
  22. enc_char = ord('a') + (ord(plaintext[i])-ord('a')+rotate_amount)%26
  23. decipher = chr(enc_char)
  24. elif plaintext[i] in alphaU:
  25. enc_char = ord('A') + (ord(plaintext[i])-ord('A')+rotate_amount)%26
  26. decipher = chr(enc_char)
  27. elif plaintext[i] in num:
  28. enc_char = ord('0') + (ord(plaintext[i])-ord('0')+rotate_amount)%10
  29. decipher = chr(enc_char)
  30. else:
  31. enc_char = ord(plaintext[i])
  32. decipher = chr(enc_char)
  33. ciphertext = ciphertext + chr(enc_char)
  34. decipher = chr(enc_char) + decipher
  35.  
  36. print "Encryption complete, ENC(%s,%s) = %s"%(plaintext,key,decipher)
  37.  
Success #stdin #stdout 0.01s 7728KB
stdin
#!/usr/bin/env python
import sys

alphaL = "abcdefghijklnmopqrstuvqxyz"
alphaU = "ABCDEFGHIJKLMNOPQRSTUVQXYZ"
num    = "0123456789"
keychars = num+alphaL+alphaU


key = "T0pS3cre7key"
if not key.isalnum():
  print "Your key is invalid, it may only be alphanumeric characters"
  sys.exit()

ciphertext = "Bot kmws mikferuigmzf rmfrxrwqe abs perudsf! Nvm kda ut ab8bv_w4ue0_ab8v_DDU"
plaintext = ""
ciphertext = ""

for i in range(len(ciphertext)):
  rotate_amount = keychars.index(key[i%len(key)])
  if plaintext[i] in alphaL:
    enc_char = ord('a') + (ord(ciphertext[i])+ord('a')+rotate_amount)%26

  elif plaintext[i] in alphaU:
    enc_char = ord('A') + (ord(ciphertext[i])+ord('A')+rotate_amount)%26

  elif plaintext[i] in num:
    enc_char = ord('0') + (ord(ciphertext[i])+ord('0')+rotate_amount)%10

  else:
    enc_char = ord(plaintext[i])

  plaintext = plaintext + chr(enc_char)
  

print "Encryption complete, ENC(%s,%s) = %s"%(plaintext,key,ciphertext)
stdout
Encryption complete, ENC(???,T0pS3cre7key) = ??