aboutsummaryrefslogtreecommitdiff
path: root/src/tests/blowfish.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/blowfish.cpp')
-rw-r--r--src/tests/blowfish.cpp118
1 files changed, 59 insertions, 59 deletions
diff --git a/src/tests/blowfish.cpp b/src/tests/blowfish.cpp
index 7c175d4..c0aba30 100644
--- a/src/tests/blowfish.cpp
+++ b/src/tests/blowfish.cpp
@@ -56,72 +56,72 @@ static const char *testdat[34][3] ={
56 56
57int main( int argc, char *argv[] ) 57int main( int argc, char *argv[] )
58{ 58{
59 MemBuf mb; 59 MemBuf mb;
60 { 60 {
61 BlowfishEcb bf( mb ); 61 BlowfishEcb bf( mb );
62 bf.setPassword( "01234567" ); 62 bf.setPassword( "01234567" );
63 for( int j = 0; j < 4; j++ ) 63 for( int j = 0; j < 4; j++ )
64 { 64 {
65 bf.write("this is a test!!"+j, 1 ); 65 bf.write("this is a test!!"+j, 1 );
66 } 66 }
67 bf.write("this is a test!!"+4, 12 ); 67 bf.write("this is a test!!"+4, 12 );
68 } 68 }
69 mb.setPos( 0 ); 69 mb.setPos( 0 );
70 BlowfishEcb bf( mb ); 70 BlowfishEcb bf( mb );
71 bf.setPassword( "01234567" ); 71 bf.setPassword( "01234567" );
72 for( int j = 0; j < 3; j++ ) 72 for( int j = 0; j < 3; j++ )
73 { 73 {
74 char c; 74 char c;
75 bf.read( &c, 1 ); 75 bf.read( &c, 1 );
76 sio << "char: '" << c << "'" << sio.nl; 76 sio << "char: '" << c << "'" << sio.nl;
77 } 77 }
78 78
79 char buf[100]; 79 char buf[100];
80 int iR = bf.read( buf, 100 ); 80 int iR = bf.read( buf, 100 );
81 buf[iR] = '\0'; 81 buf[iR] = '\0';
82 sio << "Got(" << iR << ") = '" << buf << "'" << sio.nl; 82 sio << "Got(" << iR << ") = '" << buf << "'" << sio.nl;
83 83
84 return 0; 84 return 0;
85 85
86 for( int j = 0; j < 34; j++ ) 86 for( int j = 0; j < 34; j++ )
87 { 87 {
88 MemBuf mb; 88 MemBuf mb;
89 BlowfishEcb bf( mb ); 89 BlowfishEcb bf( mb );
90 bf.setPassword( decodeStr<Hex>( testdat[j][0] ) ); 90 bf.setPassword( decodeStr<Hex>( testdat[j][0] ) );
91 bf.write( decodeStr<Hex>( testdat[j][1] ) ); 91 bf.write( decodeStr<Hex>( testdat[j][1] ) );
92 sio << "Test " << j << ": " << (mb.getString() == decodeStr<Hex>( testdat[j][2] )) << " (" << encodeStr<Hex>( mb.getString(), true ) << " == " << testdat[j][2] << ")" << sio.nl; 92 sio << "Test " << j << ": " << (mb.getString() == decodeStr<Hex>( testdat[j][2] )) << " (" << encodeStr<Hex>( mb.getString(), true ) << " == " << testdat[j][2] << ")" << sio.nl;
93 93
94 mb.setPos( 0 ); 94 mb.setPos( 0 );
95 BlowfishEcb bf2( mb ); 95 BlowfishEcb bf2( mb );
96 bf2.setPassword( decodeStr<Hex>( testdat[j][0] ) ); 96 bf2.setPassword( decodeStr<Hex>( testdat[j][0] ) );
97 char buf[8]; 97 char buf[8];
98 bf2.read( buf, 8 ); 98 bf2.read( buf, 8 );
99 99
100 sio << " - Back: " << (Bu::String(testdat[j][1]) == encodeStr<Hex>(String(buf,8),true)) << sio.nl; 100 sio << " - Back: " << (Bu::String(testdat[j][1]) == encodeStr<Hex>(String(buf,8),true)) << sio.nl;
101 } 101 }
102 102
103 { 103 {
104 File fIn("data.plain", File::Read ); 104 File fIn("data.plain", File::Read );
105 File fOut("data.crypt", File::WriteNew ); 105 File fOut("data.crypt", File::WriteNew );
106 106
107 BlowfishOfb bOut( fOut ); 107 BlowfishOfb bOut( fOut );
108 bOut.setIv("01234567"); 108 bOut.setIv("01234567");
109 bOut.setPassword("abcdefghijklmnop"); 109 bOut.setPassword("abcdefghijklmnop");
110 bOut.write( fIn.readAll() ); 110 bOut.write( fIn.readAll() );
111 } 111 }
112 { 112 {
113 File fIn("data.java", File::Read ); 113 File fIn("data.java", File::Read );
114 File fOut("data.stuff", File::WriteNew ); 114 File fOut("data.stuff", File::WriteNew );
115 115
116 BlowfishOfb bIn( fIn ); 116 BlowfishOfb bIn( fIn );
117 bIn.setIv("01234567"); 117 bIn.setIv("01234567");
118 bIn.setPassword("abcdefghijklmnop"); 118 bIn.setPassword("abcdefghijklmnop");
119 char buf[64]; 119 char buf[64];
120 bIn.read( buf, 64 ); 120 bIn.read( buf, 64 );
121 fOut.write( buf, 64 ); 121 fOut.write( buf, 64 );
122 sio << sio.nl << "All done." << sio.nl; 122 sio << sio.nl << "All done." << sio.nl;
123 } 123 }
124 124
125 return 0; 125 return 0;
126} 126}
127 127