How to break a string into left and right characters for Feistel cipher in C++?

  • C/C++
  • Thread starter davidhedoesit
  • Start date
  • Tags
    C++
In summary: If odd number of characters, pad with spaceIn summary, the program will ask the user for a text string to encrypt and a key, and then use a for loop to break up the string into left and right characters. The encryption will use 3 Feistel rounds and output the encrypted text as hexadecimal. If the input string has an odd number of characters, the program will pad the end with a space.
  • #1
davidhedoesit
2
0
Your program will ask the user for a text string to encrypt and a key (key). You will loop through the
string setting left to the first character and right to the second, and encrypt this with 3 Feistel rounds, and
output the text as hexidecimal. Continue to loop through the string using the 3rd and 4th characters and left
and right, etc. If the input string has an odd number of characters, pad the end with a space.

my problem is that i cannot figure out how to write the for loop that breaks up the string into left and right. any suggestions would be appreciated. at the bottom is the diagram i was given.
my code for the outer for loop is

i am trying to break the entered string like "The cat" up into left = T and right = h for the first loop and left = e and right = (white space)for the second loop...ect if the entered string is odd i would pad it with a space
Code:
#include <vector>
#include <cstdlib>
#include <iostream>

using namespace std;int main(){
 int left;
 int right;
 int temp;
 string userString;
 int key=0;
	 
	cout << "Enter a sting to encript: ";
	getline(cin,userString);
	
	
	
	for (int i = 0; i <= userString.length(); i++){
        left = userString.at(0);
        right= userString.at(1);
        cout<<left<<endl;
	cout<<right;
		 	
	}//through character loop
	

	
	return 0;	
}

View attachment 4950
 

Attachments

  • Screenshot (2).png
    Screenshot (2).png
    11.9 KB · Views: 79
Last edited:
Technology news on Phys.org
  • #2
Diagram of the algorithm: (Not to scale)StartPrompt User for plaintext and keyLoop through user string Set left = character 1 Set right = character 2 Encrypt using 3 Feistel roundsOutput as hexidecimalRepeat from beginning of loopEnd
 

Related to How to break a string into left and right characters for Feistel cipher in C++?

1. What is a Feistel cipher and what makes it basic?

A Feistel cipher is a type of symmetric encryption algorithm that uses a combination of substitution and permutation operations on blocks of data. It is considered basic because it is relatively simple and easy to implement, making it a popular choice for learning about encryption algorithms.

2. How does a Feistel cipher work?

A Feistel cipher operates by dividing the plaintext into left and right halves, and then performing a series of rounds in which the right half is combined with a subkey and passed through a function. The resulting output is then combined with the left half and the process is repeated for a set number of rounds, resulting in the encrypted ciphertext.

3. What are the advantages of using a Feistel cipher in C++?

Feistel ciphers have several advantages, including their simplicity and ease of implementation in programming languages like C++. They also provide a high level of security when using a sufficient number of rounds and a strong function for the round operations.

4. Are there any drawbacks to using a Basic Feistel cipher in C++?

One potential drawback of using a basic Feistel cipher in C++ is that it is vulnerable to certain types of attacks, such as differential and linear cryptanalysis. Additionally, it may not provide the same level of security as more advanced encryption algorithms.

5. How can I use a Basic Feistel cipher in my C++ programs?

To use a Basic Feistel cipher in your C++ programs, you will need to understand the algorithm and its implementation. You can find numerous resources and tutorials online that can guide you through the process of implementing a Feistel cipher in C++. Additionally, there are libraries and frameworks available that can make it easier to incorporate a Feistel cipher into your code.

Similar threads

  • Programming and Computer Science
Replies
1
Views
970
  • Programming and Computer Science
Replies
18
Views
2K
  • Programming and Computer Science
4
Replies
118
Views
7K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
4
Views
5K
  • Programming and Computer Science
Replies
3
Views
3K
  • Programming and Computer Science
Replies
4
Views
9K
  • Programming and Computer Science
Replies
3
Views
1K
Back
Top