rendered paste bodyimport java.io.*;
import java.lang.Exception;
class byteTest {
public static void main (String args[]) throws java.lang.Exception
{
long value[] = new long[5];
int eByte0 = 0, eByte1 = 0, eByte2 = 0, eByte3 = 0;
String bs0, bs1, bs2, bs3;
Writer outfile = new FileWriter("testOutput");
value[0] = 5955599;
value[1] = 7297342;
value[2] = 11497358;
value[3] = 17965269;
value[4] = 7211896;
/*
outfile.write( 97 );
outfile.write( 98 );
outfile.write( 99 );
outfile.write( 100);
*/
for(int i = 0; i < 5; i++)
{ String encryptedString = padString(Long.toBinaryString(value[i]), -32, "0");
bs0 = encryptedString.substring(0, 7+1);
bs1 = encryptedString.substring(8, 15+1);
bs2 = encryptedString.substring(16, 23+1);
bs3 = encryptedString.substring(24, 31+1);
eByte0 = Integer.parseInt( bs0, 2);
eByte1 = Integer.parseInt( bs1, 2);
eByte2 = Integer.parseInt( bs2, 2);
eByte3 = Integer.parseInt( bs3, 2);
String h0 = padString(Integer.toString(eByte0, 16), -2, "0");
String h1 = padString(Integer.toString(eByte1, 16), -2, "0");
String h2 = padString(Integer.toString(eByte2, 16), -2, "0");
String h3 = padString(Integer.toString(eByte3, 16), -2, "0");
System.out.println(value[i]);
System.out.println(encryptedString);
System.out.println(bs0 +" " + bs1 + " " + bs2 + " " + bs3);
System.out.println(eByte0 + " " + eByte1 + " " + eByte2 + " "+ eByte3);
System.out.println(h0 + " " + h1 + " " + h2 + " "+ h3);
System.out.println();
outfile.write( eByte0 );
outfile.write( eByte1 );
outfile.write( eByte2 );
outfile.write( eByte3 );
/*
outfile.write( (char)eByte0 );
outfile.write( (char)eByte1 );
outfile.write( (char)eByte2 );
outfile.write( (char)eByte3 );
outfile.write( (byte)eByte0 );
outfile.write( (byte)eByte1 );
outfile.write( (byte)eByte2 );
outfile.write( (byte)eByte3 );
*/
}
outfile.close();
}
/* Pads out a string upto padlen with pad chars
* padString("123", -8, "A") => "AAAAA123"
* padString("123", 8, "A") => "123AAAAA"
*/
private static String padString(Object str, int padlen, String pad)
{
String padding = new String();
int len = Math.abs(padlen) - str.toString().length();
if (len < 1)
return str.toString();
for (int i = 0 ; i < len ; ++i)
padding = padding + pad;
return (padlen < 0 ? padding + str : str + padding);
}
}
/*
5955599
00000000010110101110000000001111
00000000 01011010 11100000 00001111
0 90 224 15
00 5a e0 0f
7297342
00000000011011110101100100111110
00000000 01101111 01011001 00111110
0 111 89 62
00 6f 59 3e
11497358
00000000101011110110111110001110
00000000 10101111 01101111 10001110
0 175 111 142
00 af 6f 8e
17965269
00000001000100100010000011010101
00000001 00010010 00100000 11010101
1 18 32 213
01 12 20 d5
7211896
00000000011011100000101101111000
00000000 01101110 00001011 01111000
0 110 11 120
00 6e 0b 78
expected file in hex editor
00 5A E0 0F 00 6F 59 3E 00 AF 6F 8E 01 12 20 D5 00 6E 0B 78
actual file in hex editor
00 5A 88 0F 00 6F 59 3E 00 F8 6F 3F 01 12 20 CD 00 6E 0B 78
*/