Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4557
  • Last Modified:

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
0
Traltixx
Asked:
Traltixx
  • 5
  • 3
2 Solutions
 
Jaime OlivaresSoftware ArchitectCommented:
0
 
Infinity08Commented:
And here's a nice general overview with a few interesting links if you're interested in that :

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
0
 
TraltixxAuthor Commented:
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Infinity08Commented:
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.
0
 
TraltixxAuthor Commented:
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
0
 
Infinity08Commented:
If you want to know if a certain bit is set for a given character :

   char c = 'A'; /* = 65 = 0x41 */
   for (i = 0; i < 8; i++) {
     std::cout << "bit no. " << i << " of character \'" << c << "\' is : " << (int) ((c & (0x01 << i)) >> i) << std::endl;
   }

so, basically, you extract the i-th bit from the character using :

    (c & (0x01 << i)) >> i

Is that what you're looking for ? If not, can you give an example of what you want ? And what you need it for exactly ?
0
 
TraltixxAuthor Commented:
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.


0
 
Infinity08Commented:
Yes,

    0xab ^ 0x32 = 0x22

or in binary :

           10101011
    XOR 00110010
           ------------
           00100010
0
 
Infinity08Commented:
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).
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now