コード例 #1
0
  def edit(self,offset,text):

    if offset < 0:
      return False
    if offset + len(text) > len(self.encdata):
      return False
    if len(text) == 0:
      return False

    data = c18.ctrencrypt(self.encdata,self.nounce,self.key)
    tmp = data[:offset]+text+data[len(text)+offset:]
    self.encdata = c18.ctrencrypt(tmp,self.nounce,self.key)
    return True
コード例 #2
0
 def __init__(self,data):
   self.key = open("/dev/urandom").read(16)
   self.nounce = int(open("/dev/urandom").read(8).encode('hex'),16)
   self.encdata = c18.ctrencrypt(data,self.nounce,self.key)
コード例 #3
0
SGUgaGFkIGRvbmUgbW9zdCBiaXR0ZXIgd3Jvbmc=\n\
VG8gc29tZSB3aG8gYXJlIG5lYXIgbXkgaGVhcnQs\n\
WWV0IEkgbnVtYmVyIGhpbSBpbiB0aGUgc29uZzs=\n\
SGUsIHRvbywgaGFzIHJlc2lnbmVkIGhpcyBwYXJ0\n\
SW4gdGhlIGNhc3VhbCBjb21lZHk7\n\
SGUsIHRvbywgaGFzIGJlZW4gY2hhbmdlZCBpbiBoaXMgdHVybiw=\n\
VHJhbnNmb3JtZWQgdXR0ZXJseTo=\n\
QSB0ZXJyaWJsZSBiZWF1dHkgaXMgYm9ybi4="

  #### encrypting above messages
  key = open("/dev/urandom").read(16)
  cts = list()
  mxlen = 0    # max length of the CT
  milen = 999  # min length of the CT
  for msg in msgs.split("\n"):
    cts.append(c18.ctrencrypt(base64.b64decode(msg),0,key))
    l = len(cts[-1])
    if l > mxlen:
      mxlen = l
    if l < milen:
      milen = l

  #### breaking them

  # prepare the key
  key = [0]*mxlen

  # automated guessing
  key = basicautoguessing(cts,key,milen)
  key = bigrams(cts,key)
  key = trigrams(cts,key)
コード例 #4
0
  def myinput(self,s):
    s = s.replace(";","\;").replace("=","\=")
    prefix = "comment1=cooking%20MCs;userdata="
    suffix = ";comment2=%20like%20a%20pound%20of%20bacon"

    return c18.ctrencrypt(prefix+s+suffix,self.n,self.k)