Example #1
0
def basicautoguessing(cts,key,milen):

  lcts = len(cts)

  # do some basic automating guesses
  rev = range(milen)
  for i in range(milen):
    rev[i] = list()

  for i in range(lcts):
    ct = cts[i]
    for j in range(milen):
      rev[j].append(ct[j])

  for i in range(milen):
    out = c3.fcxor(rev[i])
    if out != None:
      key[i] = out[0]

  # finding the first letter (based on the most common ones):
  # from http://www.cryptograms.org/letter-frequencies.php
  for c in "TAISOCMFPWtaisocmfpw ":
    key[0] = ord(cts[0][0])^ord(c)
    revt = [ chr(ord(c1)^key[0]) for c1 in rev[0]]
    good = True
    for i in range(milen):
      if not revt[i] in string.letters+" '":
        good = False
        break
    if good == True:
      break

  return key
Example #2
0
#!/usr/bin/env python

import c3
import urllib

try:
  data = open("c4.txt").read()
except:
  data = urllib.urlopen("https://gist.github.com/tqbf/3132713/raw/40da378d42026a0731ee1cd0b2bd50f66aabac5b/gistfile1.txt").read()
  open("c4.txt","w").write(data)

for l in data.split("\n"):
  txt = c3.fcxor(l.rstrip().decode('hex'))
  if txt != None:
    print txt
Example #3
0
  return blks

if __name__ == "__main__":

  try:
    data = open("c6.txt").read()
  except:
    data = urllib.urlopen("https://gist.github.com/tqbf/3132752/raw/cecdb818e3ee4f5dda6f0847bfd90a83edb87e73/gistfile1.txt").read()
    open("c6.txt","w").write(data)

  ct = base64.b64decode(data)

  key_len = dict()
  for kl in range(2,40):
    key_len[kl] = findkeylen(ct,kl)

  for kl in sorted(key_len , key = key_len.get):
    sxor = reorderblk(ct,kl)
    key = ""
    for i in range(kl):
      txt = c3.fcxor("".join(sxor[i]))
      if txt != None:
        key += chr(txt[0])
      else:
        key += chr(0)

    if not '\x00' in key:
      print str((kl,key))
      break