Facebook
From Arash, 2 Years ago, written in Python.
This paste is a reply to Final from Arash - view diff
Embed
Download Paste or View Raw
Hits: 167
  1. import random
  2. import math as floor
  3. import enchant
  4.  
  5. validTxt = []
  6. dict = enchant.Dict("en_US")
  7.  
  8.  
  9. def genKys(length):
  10.     length *= 8
  11.     key = [0] * length
  12.     choice = int(floor.floor(random.random() * length))
  13.     for i in range(choice):
  14.         key[int(floor.floor(random.random()) * (length - 1))] = 1
  15.     return key
  16.  
  17.  
  18. def enc(plain, key):
  19.     length = len(key)
  20.     cipher = [None] * length
  21.     for i in range(length):
  22.         cipher[i] = 1 if key[i] == plain[i] else 0
  23.     return cipher
  24.  
  25.  
  26. def getBts(plain):
  27.     length = len(plain)
  28.     bits = [None] * length * 8
  29.     for i in range(length):
  30.         for j in range(8):
  31.             bits[8 * i + 7 - j] = (int)(ord(plain[i]) / pow(2, j)) % 2
  32.     return bits
  33.  
  34. def getBytes(bits):
  35.     length = len(bits)
  36.     data = []
  37.     byte = 0
  38.     for i in range((int)(length / 8)):
  39.         for j in range(8):
  40.             byte += pow(2, 7 - j) * bits[8 * i + j]
  41.         data.append(byte)
  42.         byte = 0
  43.     return data
  44.  
  45. def toString(bytes):
  46.     size = len(bytes)
  47.     output = ""
  48.     for i in range(size):
  49.         output += chr(bytes[i])
  50.     return output
  51.  
  52. def attack(i, key, size, bits, plainText):
  53.     if i == size:
  54.         dec(key, bits, plainText)
  55.         return
  56.     for j in range(1, size - i + 1):
  57.         attack(i + j, key, size, bits, plainText)
  58.         key2 = key[:]
  59.         key2[i] = 1
  60.         attack(i + j, key2, size, bits, plainText)
  61.  
  62. def dec(key, bits, plainText):
  63.     deciphered = enc(bits, key)
  64.     txt = toString(getBytes(deciphered))
  65.     if isLatin(txt) & dict.check(txt):
  66.         validTxt.append(txt)
  67.  
  68. def isLatin(txt):
  69.     size = len(txt)
  70.     for i in range(size):
  71.         if (ord(txt[i]) < 97) | (ord(txt[i]) > 122):
  72.             return False
  73.     return True

Replies to Final rss

Title Name Language When
Final Arash python 2 Years ago.