Advertisement
Guest User

Untitled

a guest
May 5th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.39 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from subprocess import call
  3.  
  4. ciphertext = 'eFjdlwKgeFlscbApnQEsny3tnye0frxnlrQ5vliW3Yx=5Al@S1nT4obQHql@Ozl@KqeG5252'
  5.  
  6. cipherlist =  [ciphertext[i:i+2] for i in range(0, len(ciphertext), 2)]
  7.  
  8.  
  9. Keys = ['TokyoTower','abuja', 'AbujaNationalMosque', 'TexasStateCapital', 'cliffsOfMoher', 'BrandenburgGate', 'DjinguereberMosque', 'OldTrafford', 'SireBobbyCharltonStand', 'PalaciodeBellasArtes', 'HassanIIMosque', 'ChristTheRedeemer', 'GreatWallOfChina', 'FortressSuomenlinna']
  10.  
  11. decoded = []
  12. totalcount = 0
  13. w, h = 8, 8
  14.  
  15. def find(target):
  16.     for i,lst in enumerate(Matrix):
  17.         for j,entry in enumerate(lst):
  18.             if entry == target:
  19.                 return (i, j)
  20.     return (None, None)
  21.  
  22. for keycount, key in enumerate(Keys):
  23.     AlphabetU = ['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']
  24.     AlphabetL = ['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', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '=', '@']
  25.     xcount = 0
  26.     ycount = 0
  27.     Matrix = [[0 for x in range(w)] for y in range(h)]
  28.  
  29.     for characters in Keys[keycount].upper():
  30.         if characters in AlphabetU:
  31.             Matrix[ycount][xcount] = characters
  32.             AlphabetU.remove(characters)
  33.         else:
  34.             continue
  35.         xcount += 1
  36.         totalcount += 1
  37.         if xcount == 8:
  38.             ycount += 1
  39.             xcount = 0
  40.  
  41.     for holder, alphabetEntries in enumerate(AlphabetU):
  42.         Matrix[ycount][xcount] = AlphabetU[(holder)]
  43.         xcount += 1
  44.         totalcount += 1
  45.         if xcount == 8:
  46.             ycount += 1
  47.             xcount = 0
  48.  
  49.     for characters in Keys[keycount].lower():
  50.         if characters in AlphabetL:
  51.             Matrix[ycount][xcount] = characters
  52.             AlphabetL.remove(characters)
  53.         else:
  54.             continue
  55.         xcount += 1
  56.         totalcount += 1
  57.         if xcount == 8:
  58.             ycount += 1
  59.             xcount = 0
  60.  
  61.     for holder, alphabetEntries in enumerate(AlphabetL):
  62.         Matrix[ycount][xcount] = AlphabetL[(holder)]
  63.         xcount += 1
  64.         totalcount += 1
  65.         if xcount == 8:
  66.             ycount += 1
  67.             xcount = 0
  68.  
  69.     #for elements in Matrix:
  70.     #   print elements
  71.     #print '\n'
  72.  
  73.     #DECRYPTION HERE
  74.     for touples in cipherlist:
  75.         firstpart, secondpart = touples[::2], touples[1::2]
  76.         p, q = find(firstpart)
  77.         a, b = find(secondpart)
  78.  
  79.         #If the two letters appear on the same row in the square, then replace each letter by the letter immediately to the left of it in the square (cycling round to the right hand side if necessary).
  80.         if q == b:
  81.             p = p - 1
  82.             if p < 0:
  83.                 p = p + 8
  84.             a = a - 1
  85.             if a < 0:
  86.                 a = a + 8
  87.             TransA = Matrix[p][q]
  88.             TransB = Matrix[a][b]
  89.         #If the two letters appear in the same column in the square, then replace each letter by the letter immediately above it in the square (cycling round to the bottom of the square if necessary).
  90.         elif p == a:
  91.             q = q - 1
  92.             if q < 0:
  93.                 q = q + 8
  94.             b = b - 1
  95.             if b < 0:
  96.                 b = b + 8
  97.             TransA = Matrix[p][q]
  98.             TransB = Matrix[a][b]
  99.         else:
  100.             TransA = Matrix[p][b]
  101.             TransB = Matrix[a][q]
  102.         temp = '@'
  103.         if TransA is temp:
  104.             TransA = '●'
  105.         if TransB is temp:
  106.             TransB = '●'
  107.         decoded.append(TransA)
  108.         decoded.append(TransB)
  109.  
  110.     decoded = ''.join(decoded)
  111.     print decoded
  112.     #decrypted = call(['openssl', 'aes-256-cbc', '-d', '-a', '-in', 'challenge8-solution-real.txt.enc', '-out', 'decrypted/' + key + '-decrypted.txt', '-k', decoded])
  113.     decoded = []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement