Exemplo n.º 1
0
#Kabopan - Readable Algorithms. Public Domain, 2007-2009

from kbp.types import ( \
 sub_string, add_string, 
 Str, List, 
 Byte, Dword, Word, Qword, Oword, DQword)

assert sub_string("abc", "aBc") == "_B_"
assert add_string("abc", "_B_") == "aBc"

s = Str("abcdefghij")
assert [ s,           s << 1,       s >> 1,       (s << 1) >> 1, s << 2,       s << 3,      s << 4] == \
       ['abcdefghij', 'bcdefghija', 'jabcdefghi', 'abcdefghij', 'cdefghijab', 'defghijabc', 'efghijabcd']

assert s.setstart("d") == "defghijabc"

s = Str('abcaba')
assert s.indexes("a") == [0, 3, 5]
assert s.indexes("d") == []

s = Str("abcdefghij")
import pprint
assert [s.insert("1", 2), s.insert("12", 2), s.overwrite("1", 2), s.overwrite("12", 2)] == \
       ['ab1cdefghij',   'ab12cdefghij',     'ab1defghij',        'ab12efghij']

assert [s.splitblock(2), s.splitblock(3)] == [['ab', 'cd', 'ef', 'gh', 'ij'], ['abc', 'def', 'ghi', 'j']]
 

assert List([1, 2, 3, 4]) >> 1 == [4, 1, 2, 3]
assert List([1, 2, 3, 4]) >> 4 == [1, 2, 3, 4]
assert List([1, 2, 3, 4]) << 1 == [2, 3, 4, 1]
Exemplo n.º 2
0
    0xd9130a8164549fe818874806e1c7014b,
    0xd79e1c308aa5bbcdeea8ed63df412da9,
    0x043f8582f241db351ce627e153e7f0e4,
    0xe33b4ddc9c38f2199c3e7b164fcc0536]

# collision, XiaoyunWang, Dengguo Feng, Xuejia Lai, Hongbo Yu, 2004

a4 = \
 "839c7a4d 7a92cb56 78a5d5b9 eea5a757 3c8a74de b366c3dc 20a083b6 9f5d2a3b"\
 "b3719dc6 9891e9f9 5e809fd7 e8b23ba6 318edd45 e51fe397 08bf9427 e9c3e8b9"

delta4 = \
 "_______________d________2______________________________________________"\
 "_________________________________________c_____________________________"

b4 = add_string(a4, delta4)
b4 = b4.replace(" ","")
a4, b4 = [hex2bin(s) for s in [a4, b4]]



assert Md4_u.IVs == md4_IVs, "md4 IVs"
check_test_vectors(hashmd4, md4_test_vectors, "MD4")

assert hashmd4(a4) == hashmd4(b4)

# MD5
hashmd5 = lambda x: Md5().compute(x).digest()

md5_test_vectors = [
    0xd41d8cd98f00b204e9800998ecf8427e,
Exemplo n.º 3
0
 "f96e68be bb0025d2 d2b69edf 21724198 f688b41d eb9b4913 fbe696b5 457ab399"\
 "21e1d759 1f89de84 57e8613c 6c9e3b24 2879d4d8 783b2d9c a9935ea5 26a729c0"\
 "6edfc501 37e69330 be976012 cc5dfe1c 14c4c68b d1db3ecb 24438a59 a09b5db4"\
 "35563e0d 8bdf572f 77b53065 cef31f32 dc9dbaa0 4146261e 9994bd5c d0758e3d"

delta = \
 "__________________________________1_______d_________1_b________d_______"\
 "a______5_______f___________3_____2__a______d________0_3_____e__7______c"\
 "6______d_6_____7_________e_4________d________e_________________________"\
 "________________1_______6_________d_1________a________3______1_______c_"\
 "7_____f_________0_5______d_a_____d__7______f_6______1_7_____f__c_______"\
 "a_____1__9______6__________e______6_a_____9_________e_2______7_a_____8_"\
 "_______3__________3______0_4_____5_________9_5________a________2_______"\
 "__________________________________0_______e_________c_1________5_______" 

b = add_string(a, delta)
b = b.replace(" ","")
a, b = [hex2bin(s) for s in [a, b]]

assert hash0(a) == hash0(b), "sha-0 collision"

#sha-1
hash1 = lambda x: Sha1().compute(x).digest()


sha1_test_vectors = [
    0xDA39A3EE5E6B4B0D3255BFEF95601890AFD80709,
    0x86F7E437FAA5A7FCE15D1DDCB9EAEAEA377667B8,
    0xA9993E364706816ABA3E25717850C26C9CD0D89D,
    0xC12252CEDA8BE8994D5FA0290A47231C1D16AAE3,
    0x32D10C7B8CF96570CA04CE37F2A19D84240D3A89,
Exemplo n.º 4
0
#Kabopan - Readable Algorithms. Public Domain, 2007-2009

from kbp.types import ( \
 sub_string, add_string,
Str, List,
Byte, Dword, Word, Qword, Oword, DQword)

assert sub_string("abc", "aBc") == "_B_"
assert add_string("abc", "_B_") == "aBc"

s = Str("abcdefghij")
assert [ s,           s << 1,       s >> 1,       (s << 1) >> 1, s << 2,       s << 3,      s << 4] == \
       ['abcdefghij', 'bcdefghija', 'jabcdefghi', 'abcdefghij', 'cdefghijab', 'defghijabc', 'efghijabcd']

assert s.setstart("d") == "defghijabc"

s = Str('abcaba')
assert s.indexes("a") == [0, 3, 5]
assert s.indexes("d") == []

s = Str("abcdefghij")
import pprint
assert [s.insert("1", 2), s.insert("12", 2), s.overwrite("1", 2), s.overwrite("12", 2)] == \
       ['ab1cdefghij',   'ab12cdefghij',     'ab1defghij',        'ab12efghij']

assert [s.splitblock(2), s.splitblock(3)] == [['ab', 'cd', 'ef', 'gh', 'ij'],
                                              ['abc', 'def', 'ghi', 'j']]

assert List([1, 2, 3, 4]) >> 1 == [4, 1, 2, 3]
assert List([1, 2, 3, 4]) >> 4 == [1, 2, 3, 4]
assert List([1, 2, 3, 4]) << 1 == [2, 3, 4, 1]
Exemplo n.º 5
0
 "f96e68be bb0025d2 d2b69edf 21724198 f688b41d eb9b4913 fbe696b5 457ab399"\
 "21e1d759 1f89de84 57e8613c 6c9e3b24 2879d4d8 783b2d9c a9935ea5 26a729c0"\
 "6edfc501 37e69330 be976012 cc5dfe1c 14c4c68b d1db3ecb 24438a59 a09b5db4"\
 "35563e0d 8bdf572f 77b53065 cef31f32 dc9dbaa0 4146261e 9994bd5c d0758e3d"

delta = \
 "__________________________________1_______d_________1_b________d_______"\
 "a______5_______f___________3_____2__a______d________0_3_____e__7______c"\
 "6______d_6_____7_________e_4________d________e_________________________"\
 "________________1_______6_________d_1________a________3______1_______c_"\
 "7_____f_________0_5______d_a_____d__7______f_6______1_7_____f__c_______"\
 "a_____1__9______6__________e______6_a_____9_________e_2______7_a_____8_"\
 "_______3__________3______0_4_____5_________9_5________a________2_______"\
 "__________________________________0_______e_________c_1________5_______"

b = add_string(a, delta)
b = b.replace(" ", "")
a, b = [hex2bin(s) for s in [a, b]]

assert hash0(a) == hash0(b), "sha-0 collision"

#sha-1
hash1 = lambda x: Sha1().compute(x).digest()

sha1_test_vectors = [
    0xDA39A3EE5E6B4B0D3255BFEF95601890AFD80709,
    0x86F7E437FAA5A7FCE15D1DDCB9EAEAEA377667B8,
    0xA9993E364706816ABA3E25717850C26C9CD0D89D,
    0xC12252CEDA8BE8994D5FA0290A47231C1D16AAE3,
    0x32D10C7B8CF96570CA04CE37F2A19D84240D3A89,
    0x761C457BF73B14D27E9E9265C46F4B4DDA11F940,
Exemplo n.º 6
0
    0xa448017aaf21d8525fc10ae87aa6729d, 0xd9130a8164549fe818874806e1c7014b,
    0xd79e1c308aa5bbcdeea8ed63df412da9, 0x043f8582f241db351ce627e153e7f0e4,
    0xe33b4ddc9c38f2199c3e7b164fcc0536
]

# collision, XiaoyunWang, Dengguo Feng, Xuejia Lai, Hongbo Yu, 2004

a4 = \
 "839c7a4d 7a92cb56 78a5d5b9 eea5a757 3c8a74de b366c3dc 20a083b6 9f5d2a3b"\
 "b3719dc6 9891e9f9 5e809fd7 e8b23ba6 318edd45 e51fe397 08bf9427 e9c3e8b9"

delta4 = \
 "_______________d________2______________________________________________"\
 "_________________________________________c_____________________________"

b4 = add_string(a4, delta4)
b4 = b4.replace(" ", "")
a4, b4 = [hex2bin(s) for s in [a4, b4]]

assert Md4_u.IVs == md4_IVs, "md4 IVs"
check_test_vectors(hashmd4, md4_test_vectors, "MD4")

assert hashmd4(a4) == hashmd4(b4)

# MD5
hashmd5 = lambda x: Md5().compute(x).digest()

md5_test_vectors = [
    0xd41d8cd98f00b204e9800998ecf8427e, 0x0cc175b9c0f1b6a831c399e269772661,
    0x900150983cd24fb0d6963f7d28e17f72, 0xf96b697d7cb7938d525a2f31aaf161d0,
    0xc3fcd3d76192e4007dfb496cca67e13b, 0xd174ab98d277d9f5a5611c2c9f419d9f,