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

Replies to Final rss

Title Name Language When
Final Arash python 2 Years ago.