In [7]:
class MyException(Exception):
    pass

def unpad2(s):
    n=s[-1:]
    i=ord(n)
    if all(map(lambda x: x==n, s[-i:])):
        return s[:-i]
    else:
        raise MyException("Bad Padding!")

In [8]:
unpad2("ICE ICE BABY\x04\x04\x04\x04")


Out[8]:
'ICE ICE BABY'

In [9]:
unpad2("ICE ICE BABY\x05\x05\x05\x05")


---------------------------------------------------------------------------
MyException                               Traceback (most recent call last)
<ipython-input-9-7633853194f6> in <module>()
----> 1 unpad2("ICE ICE BABY\x05\x05\x05\x05")

<ipython-input-7-9db45f1ff470> in unpad2(s)
      8         return s[:-i]
      9     else:
---> 10         raise MyException("Bad Padding!")

MyException: Bad Padding!

In [10]:
unpad2("ICE ICE BABY\x01\x02\x03\x04")


---------------------------------------------------------------------------
MyException                               Traceback (most recent call last)
<ipython-input-10-a68f9990457c> in <module>()
----> 1 unpad2("ICE ICE BABY\x01\x02\x03\x04")

<ipython-input-7-9db45f1ff470> in unpad2(s)
      8         return s[:-i]
      9     else:
---> 10         raise MyException("Bad Padding!")

MyException: Bad Padding!

In [10]:


In [13]:
import sys
sys.path.insert(0,'..')
from blockcrypto import *
globalkey=randomkey(16)
iv = randomkey(16)

In [60]:
import string
def f1(s,key,iv):
    s=s.replace("=","")
    s=s.replace("&","")
    s=s.replace(";","")
    news = pad("comment1=cooking%20MCs;userdata=" + s + ";comment2=%20like%20a%20pound%20of%20bacon", 16)
    return encryptCBCAES(key,news, iv)

def f2(s,key,iv):
    s=decryptCBCAES(key,s,iv)
    print s
    #print [s[i:i+16] for i in range(0, len(s), 16)]
    if string.find(s,";admin=true;")!=-1:
        return True
    else:
        return False

In [61]:
test=f1("AadminAtrue", globalkey, iv)
#test=test[:16]+chr(ord(test[16])+5) + test[17:]
#test=test[:16+6] + chr(ord(test[16+6])+1) + test[16+7:]
test=test[:16]+chr(ord("A")^ord(";")^ord(test[16])) + test[17:]
test=test[:16+6] + chr(ord("A")^ord("=")^ord(test[16+6])) + test[16+7:]
f2(test,globalkey,iv)


���>/������;admin=true;comment2=%20like%20a%20pound%20of%20bacon
Out[61]:
True

In [57]:



Out[57]:
124

In [ ]: