Traltixx
asked on
Feistel-type cipher in C++
Hi,
Im trying to implement a feistel-type cipher in C++. I was wondering if there already exists such a cipher written in C++? or any other common/extensible programming language such as java,c or perl/python? I've tried to search abit and it seems that most feistel ciphers doesnt come with its source code or that its compiled executeable is only available.
Anyone know where i might find this in C++?
Thanks
Im trying to implement a feistel-type cipher in C++. I was wondering if there already exists such a cipher written in C++? or any other common/extensible programming language such as java,c or perl/python? I've tried to search abit and it seems that most feistel ciphers doesnt come with its source code or that its compiled executeable is only available.
Anyone know where i might find this in C++?
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for that.
I was also wondering if there is a function in C++ to convert a single character to a 16 digit binary representation of its ASCII value and convert it back.
I was also wondering if there is a function in C++ to convert a single character to a 16 digit binary representation of its ASCII value and convert it back.
A normal (8-bit) character is an integer value itself, so you can easily retrieve its value :
char c = 'A'; /* = 65 = 0x41 */
fprintf(stdout, "int val of char \'%c\' : %d = 0x%02x\n", c, (int) c, (int) c); /* C style :) */
Do I understand you correctly that you want to retrieve a string containing the binary representation of the character ?
char c = 'A'; /* = 65 = 0x41 */
and get :
char *s = "01000001";
?
If so, you can use itoa() for this :
http://www.cplusplus.com/ref/cstdlib/itoa.html
If you just want the integer value, cast the character to an int, and that's it.
char c = 'A'; /* = 65 = 0x41 */
fprintf(stdout, "int val of char \'%c\' : %d = 0x%02x\n", c, (int) c, (int) c); /* C style :) */
Do I understand you correctly that you want to retrieve a string containing the binary representation of the character ?
char c = 'A'; /* = 65 = 0x41 */
and get :
char *s = "01000001";
?
If so, you can use itoa() for this :
http://www.cplusplus.com/ref/cstdlib/itoa.html
If you just want the integer value, cast the character to an int, and that's it.
ASKER
sorry, you are right..what I meant was I want to get the binary representation of a character or hex and covert it back to the character again.
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes.thats exactly what Im looking for.
Thanks.
Also a quick question if I do a ^ (xor) operator on two single chars, would it give me the bit-by-bit XOR result? I was assuming it did, but would like the feedback.
Thanks.
Also a quick question if I do a ^ (xor) operator on two single chars, would it give me the bit-by-bit XOR result? I was assuming it did, but would like the feedback.
Yes,
0xab ^ 0x32 = 0x22
or in binary :
10101011
XOR 00110010
------------
00100010
0xab ^ 0x32 = 0x22
or in binary :
10101011
XOR 00110010
------------
00100010
Let me just repeat this to make sure : a char is an integer type, so it can be treated as any other integer type (including the (bitwise) operations you can do on them).
http://en.wikipedia.org/wiki/Feistel_network
One of the best known Feistel ciphers is Blowfish ... on the official site, you can find reference source code :
http://www.schneier.com/blowfish-download.html