aboutsummaryrefslogtreecommitdiff
path: root/src/tests/blowfish.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-04-09 16:29:18 +0000
committerMike Buland <eichlan@xagasoft.com>2012-04-09 16:29:18 +0000
commit228b885b41652a015a91770dfd993456d76ad102 (patch)
tree9a4b0756133fa1b7553f9aacf9ad50e7f26179d8 /src/tests/blowfish.cpp
parentb93f18e1dd303fb648bc350416f7f5ace536fd1f (diff)
downloadlibbu++-228b885b41652a015a91770dfd993456d76ad102.tar.gz
libbu++-228b885b41652a015a91770dfd993456d76ad102.tar.bz2
libbu++-228b885b41652a015a91770dfd993456d76ad102.tar.xz
libbu++-228b885b41652a015a91770dfd993456d76ad102.zip
Blowfish works in it's new split form, which will make it much easier to add
other types of ciphers down the road, should we choose to.
Diffstat (limited to 'src/tests/blowfish.cpp')
-rw-r--r--src/tests/blowfish.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/tests/blowfish.cpp b/src/tests/blowfish.cpp
new file mode 100644
index 0000000..c7486e1
--- /dev/null
+++ b/src/tests/blowfish.cpp
@@ -0,0 +1,93 @@
1#include <bu/blowfish.h>
2#include <bu/file.h>
3#include <bu/membuf.h>
4#include <bu/hex.h>
5#include <bu/strfilter.h>
6#include <bu/sio.h>
7
8using namespace Bu;
9
10static const char *testdat[34][3] ={
11{"0000000000000000", "0000000000000000", "4EF997456198DD78"},
12{"FFFFFFFFFFFFFFFF", "FFFFFFFFFFFFFFFF", "51866FD5B85ECB8A"},
13{"3000000000000000", "1000000000000001", "7D856F9A613063F2"},
14{"1111111111111111", "1111111111111111", "2466DD878B963C9D"},
15{"0123456789ABCDEF", "1111111111111111", "61F9C3802281B096"},
16{"1111111111111111", "0123456789ABCDEF", "7D0CC630AFDA1EC7"},
17{"0000000000000000", "0000000000000000", "4EF997456198DD78"},
18{"FEDCBA9876543210", "0123456789ABCDEF", "0ACEAB0FC6A0A28D"},
19{"7CA110454A1A6E57", "01A1D6D039776742", "59C68245EB05282B"},
20{"0131D9619DC1376E", "5CD54CA83DEF57DA", "B1B8CC0B250F09A0"},
21{"07A1133E4A0B2686", "0248D43806F67172", "1730E5778BEA1DA4"},
22{"3849674C2602319E", "51454B582DDF440A", "A25E7856CF2651EB"},
23{"04B915BA43FEB5B6", "42FD443059577FA2", "353882B109CE8F1A"},
24{"0113B970FD34F2CE", "059B5E0851CF143A", "48F4D0884C379918"},
25{"0170F175468FB5E6", "0756D8E0774761D2", "432193B78951FC98"},
26{"43297FAD38E373FE", "762514B829BF486A", "13F04154D69D1AE5"},
27{"07A7137045DA2A16", "3BDD119049372802", "2EEDDA93FFD39C79"},
28{"04689104C2FD3B2F", "26955F6835AF609A", "D887E0393C2DA6E3"},
29{"37D06BB516CB7546", "164D5E404F275232", "5F99D04F5B163969"},
30{"1F08260D1AC2465E", "6B056E18759F5CCA", "4A057A3B24D3977B"},
31{"584023641ABA6176", "004BD6EF09176062", "452031C1E4FADA8E"},
32{"025816164629B007", "480D39006EE762F2", "7555AE39F59B87BD"},
33{"49793EBC79B3258F", "437540C8698F3CFA", "53C55F9CB49FC019"},
34{"4FB05E1515AB73A7", "072D43A077075292", "7A8E7BFA937E89A3"},
35{"49E95D6D4CA229BF", "02FE55778117F12A", "CF9C5D7A4986ADB5"},
36{"018310DC409B26D6", "1D9D5C5018F728C2", "D1ABB290658BC778"},
37{"1C587F1C13924FEF", "305532286D6F295A", "55CB3774D13EF201"},
38{"0101010101010101", "0123456789ABCDEF", "FA34EC4847B268B2"},
39{"1F1F1F1F0E0E0E0E", "0123456789ABCDEF", "A790795108EA3CAE"},
40{"E0FEE0FEF1FEF1FE", "0123456789ABCDEF", "C39E072D9FAC631D"},
41{"0000000000000000", "FFFFFFFFFFFFFFFF", "014933E0CDAFF6E4"},
42{"FFFFFFFFFFFFFFFF", "0000000000000000", "F21E9A77B71C49BC"},
43{"0123456789ABCDEF", "0000000000000000", "245946885754369A"},
44{"FEDCBA9876543210", "FFFFFFFFFFFFFFFF", "6B5C5A9C5D9E0A5A"}};
45
46
47int main( int argc, char *argv[] )
48{
49
50 for( int j = 0; j < 34; j++ )
51 {
52 MemBuf mb;
53 Blowfish bf( mb );
54 bf.setPassword( decodeStr<Hex>( testdat[j][0] ) );
55 bf.write( decodeStr<Hex>( testdat[j][1] ) );
56 sio << "Test " << j << ": " << (mb.getString() == decodeStr<Hex>( testdat[j][2] )) << " (" << encodeStr<Hex>( mb.getString(), true ) << " == " << testdat[j][2] << ")" << sio.nl;
57
58 mb.setPos( 0 );
59 Blowfish bf2( mb );
60 bf2.setPassword( decodeStr<Hex>( testdat[j][0] ) );
61 char buf[8];
62 bf2.read( buf, 8 );
63
64 sio << " - Back: " << (Bu::String(testdat[j][1]) == encodeStr<Hex>(String(buf,8),true)) << sio.nl;
65 }
66
67 /*
68 {
69 File fIn("data.plain", File::Read );
70 File fOut("data.crypt", File::WriteNew );
71
72 Blowfish bOut( fOut );
73 bOut.setPassword("abcdefghijklmnop");
74 bOut.write( fIn.readAll() );
75 }
76 */
77 /*
78 {
79 File fIn("data.java", File::Read );
80 File fOut("data.stuff", File::WriteNew );
81
82 Blowfish bIn( fIn );
83 bIn.setPassword("abcdefghijklmnop");
84 char buf[64];
85 bIn.read( buf, 64 );
86 fOut.write( buf, 64 );
87 sio << sio.nl << "All done." << sio.nl;
88 }
89 */
90
91 return 0;
92}
93