コード例 #1
0
ファイル: two.py プロジェクト: de-py/Course-AppliedCrypto
def is_padding(the_string, block_size):
    hx = the_string.encode("hex")
    hx = rypto.split(hx, 2)
    last = hx[-1]  #Last byte in string
    num_bytes = int(last, 16)

    if num_bytes == 1:
        block_size_check(the_string,
                         block_size)  #Checks to make sure valid to block size
        print 'Assuming it is ACTUALLY only padded with one byte:'  #If it made it past block size check
        return rypto.unpad(the_string, block_size)

    else:
        try:
            same_byte_check(
                hx, num_bytes
            )  #Checks for ending in correct number of bytes and the same byte
            block_size_check(
                the_string, block_size
            )  #Checks again blocksize with default padding function
            return rypto.unpad(
                the_string, block_size
            )  #Returns block size with assumption it made it this far without errors
        except ValueError as e:
            raise
コード例 #2
0
def prep_cbc(s, k, iv, bs):

    final = ''
    #Splits into 16 byte blocks
    s = rypto.split(s, 32)

    #Converts to ascii, kinda. Just required of AES function.
    k = k.decode("hex")

    #Inserts iv to the beginning of the block for the for loop
    s.insert(0, iv)

    #Cycle through all blocks
    for i in range(1, len(s)):
        x = cbc_decrypt(s[i], k, s[i - 1])  #Decrypts and sends iv as s[i-1]
        final += x.decode("hex")  #Decodes reponse

    return rypto.unpad(final, bs)  #Unpads and returns
コード例 #3
0
ファイル: one.py プロジェクト: de-py/Course-AppliedCrypto
    if rem == 0:
        blocks = value

    else:
        blocks = value + 1

    return blocks


if __name__ == "__main__":
    message = open("w8.txt").readlines()
    for l, q in enumerate(message):
        sentence = ''
        q = q.decode("base64")
        webapp = rypto.webapp()  #encryption class (oracle)
        enc = webapp.encrypt(q)  #encrypted value

        num_blocks = num_of_blocks(enc)

        for m in range(0, num_blocks):  #For every block (after 0)
            try:
                sentence += single_block(enc, m)  #Check for one block
            except ValueError as e:
                print "I guess were skipping this one"

        print 'Message', l
        try:
            print rypto.unpad(sentence, 128)
        except ValueError as e:
            print sentence
コード例 #4
0
ファイル: two.py プロジェクト: de-py/Course-AppliedCrypto
def block_size_check(b_string, block_size):
    try:
        rypto.unpad(b_string, block_size)

    except Exception:
        raise ValueError('The padding bytes do not match the block size')