def generate_keys(key_text):
    """ key generation
    """
    key = []
    for i in key_text:
        key.extend(to_binary(ord(i)))

    C = []
    D = []
    r = []
    for i in range(28):
        C.append(key[PC1_C[i]])
    for i in range(28):
        D.append(key[PC1_D[i]])
    for i in range(0, 16):
        if i in [0, 1, 8, 15]:
            C = left_shift(C, 1)
            D = left_shift(D, 1)
        else:
            C = left_shift(C, 2)
            D = left_shift(D, 2)
        CD = []
        CD.extend(C)
        CD.extend(D)
        dummy = []
        for i in range(48):
            dummy.append(CD[PC2[i]])
        r.append(dummy)
    return r
Example #2
0
def generate_keys(key_text):
    #merubah key menjadi biner
    key = []
    for i in key_text:
        key.extend(to_binary(ord(i)))
    # print
    # print key

    C = []
    D = []
    r = []
    # iv_new = []
    for i in range(28):
        C.append(key[PC1_C[i]])
    # print "array C = "
    # print C
    # print "==="
    for i in range(28):
        D.append(key[PC1_D[i]])
    for i in range(0, 16):
        if i in [0, 1, 8, 15]:
            C = left_shift(C, 1)
            D = left_shift(D, 1)
        else:
            C = left_shift(C, 2)
            D = left_shift(D, 2)
        CD = []
        CD.extend(C)
        CD.extend(D)
        dummy = []
        for i in range(48):
            dummy.append(CD[PC2[i]])
        r.append(dummy)
    return r
Example #3
0
def generate_keys(key_text):
    """ key generation
    """
    key = []
    for i in key_text:
        key.extend(to_binary(ord(i)))

    C = []
    D = []
    r = []
    for i in range(28):
        C.append(key[PC1_C[i]])
    for i in range(28):
        D.append(key[PC1_D[i]])
    for i in range(0, 16):
        if i in [0, 1, 8, 15]:
            C = left_shift(C, 1)
            D = left_shift(D, 1)
        else:
            C = left_shift(C, 2)
            D = left_shift(D, 2)
        CD = []
        CD.extend(C)
        CD.extend(D)
        dummy = []
        for i in range(48):
            dummy.append(CD[PC2[i]])
        r.append(dummy)
    return r
Example #4
0
def split_header_and_content(img):
    """plain text to binary, split header and content for image
    """
    text_bits = []
    for i in img:
        text_bits.extend(to_binary(ord(i)))
    header_bits = text_bits[0:HEADER_LENGTH]
    text_bits = text_bits[HEADER_LENGTH:]
    return header_bits, text_bits
Example #5
0
def s_box(block):
    #menyimpelkan blok 48bit menjadi 32bit dengan cara membuat tabelnya
    #yang bisa paling pinggirnya
    for i in range(0, 8):
        row = str(block[i][0]) + str(block[i][-1])
        column = ''
        for j in range(1, 5):
            column += str(block[i][j])
        a = 16 * get_row(row)
        a += get_column(column)
        block.pop(i)
        block.insert(i, to_binary(ord(chr(s[i][a]))))
    r = []
    for i in block:
        r.extend(i[4:8])
    return r
def s_box(block):
    """s-box function to reduce 48 bit block to 32 bit block
    """
    for i in range(0, 8):
        row = str(block[i][0]) + str(block[i][-1])
        column = ''
        for j in range(1, 5):
            column += str(block[i][j])
        a = 16 * get_row(row)
        a += get_column(column)
        block.pop(i)
        block.insert(i, to_binary(ord(chr(s[i][a]))))
    r = []
    for i in block:
        r.extend(i[4:8])
    return r
Example #7
0
def s_box(block):
    """s-box function to reduce 48 bit block to 32 bit block
    """
    for i in range(0, 8):
        row = str(block[i][0]) + str(block[i][-1])
        column = ''
        for j in range(1, 5):
            column += str(block[i][j])
        a = 16 * get_row(row)
        a += get_column(column)
        block.pop(i)
        block.insert(i, to_binary(ord(chr(s[i][a]))))
    r = []
    for i in block:
        r.extend(i[4:8])
    return r
Example #8
0
def get_bits(plaintext):
    text_bits = []
    for i in plaintext:
        text_bits.extend(to_binary(ord(i)))
    return text_bits
Example #9
0
def get_bits(plaintext):
    text_bits = []
    for i in plaintext:
        text_bits.extend(to_binary(ord(i)))
    return text_bits