1

Topic: The cipher of Gronsfelda

It is necessary to make so that if character number (encrypted_message [count]) at an encryption was more than 255 (ASCII the coding) that was ciphered under the formula:

 encrypted_message [count] =encrypted_message [count]-224. 

The Item with. I at obtaining of number of the character have more 255, counting begins with the beginning and then the formula is necessary

 encrypted_message [count] =encrypted_message [count] +32 

,
But how to implement it in the code I do not know.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main () {
setlocale (0, "");
int count, j;
char key [20];
char message [100];
std:: ifstream fin ("E: \\message.txt", std:: ios:: in);
if (fin.is_open ()) {
fin.getline (message, 50);
fin.close ();
}
printf ("\nEnter Key:\t");
fflush (stdin);
scanf ("% [^ \n] s", key);
int message_length = strlen (message), key_length = strlen (key);
char temp_key [message_length], encrypted_message [message_length], decrypted_message [message_length];
for (count = 0, j = 0; count <message_length; ++ count, ++ j) {
if (j == key_length) {
j = 0;
}
temp_key [count] = key [j];
}
temp_key [count] = '\0 ';
count = 0;
while (count <message_length) {
encrypted_message [count] = ((message [count] + (temp_key [count] - 48)));
count = count + 1;
}
for (int count = 0; count <message_length; count + 1)
encrypted_message [count] = '\0 ';
count = 0;
while (count <message_length) {
decrypted_message [count] = ((encrypted_message [count] - (temp_key [count] - 48)));
count = count + 1;
}
decrypted_message [count] = '\0 ';
printf ("\n-------------------------------\n");
printf ("\nIntial String:\t%s", message);
printf ("\nKey:\t%s", key);
printf ("\nGenerated Key:\t%s", temp_key);
printf ("\nEncrypted Message:\t%s", encrypted_message);
printf ("\nDecrypted Message:\t%s", decrypted_message);
return 0;
}

2

Re: The cipher of Gronsfelda

Vvvv111, I understood nothing. Learn to express thought and to write the readable code.

3

Re: The cipher of Gronsfelda

, to unit there corresponds 49 code in ASCII to the coding, and for correct input is subtracted 48, i.e. at input of a key 1 (49-48=1) to the character code of a letter is added 1, and so on with other digits

4

Re: The cipher of Gronsfelda

Here the full statement of the job, can so it will be more clear.

wrote:

 the Program ciphering and  ordinary text ASCII files by means of the advanced cipher of Gronsfelda. 

Instructions:

 Shifr Gronsfelda has a key - 5 (in our case any amount) digits. The ciphered text breaks into symbol groups (gaps - not an exception) on number of digits in a key.
The code of the first character of group increases by the number corresponding to the first digit of a key, the code of the second on the number corresponding to the second digit of a key etc.
Thus the codes it is less 32 (so-called control characters) are not subject to conversion
(In order to avoid damage of structure of a file and other unpleasant consequences). At a de-encryption reverse process (reduction of the codes) is produced. 

If the code received at enciphering the CODE is more 255, we apply the formula the CODE = the CODE - 224.
If received at  the code the CODE less than 32 we apply the formula the CODE = the CODE + 224.
Thus,  sequence of the codes 32 - 255.
Naturally, at an encryption and decoding the program should zaprashi-vat at the user a key.

5

Re: The cipher of Gronsfelda

Vvvv111 wrote:

Here the full statement of the job, can so it will be more clear.

Principal  in that what place from this very simple job causes in you
Difficulty.

6

Re: The cipher of Gronsfelda

Vvvv111 wrote:

Here the full statement of the job, can so it will be more clear.
The program ciphering and  ordinary text ASCII files by means of the advanced cipher of Gronsfelda.
Instructions: the Cipher of Gronsfelda has a key - 5 (in our case any amount) digits. The ciphered text breaks into symbol groups (about-are white - not an exception) on number of digits in a key. The code of the first character of group increases by the number corresponding to the first digit of a key, the code of the second on the number corresponding to the second digit of a key etc. Thus the codes less 32 (so-called control characters) to conversion are not subject (in order to avoid damage of structure of a file and other unpleasant consequences). At a de-encryption reverse process (reduction of the codes) is produced.
If the code received at enciphering the CODE is more 255, we apply the formula the CODE = the CODE - 224.
If received at  the code the CODE less than 32 we apply the formula the CODE = the CODE + 224.
Thus,  sequence of the codes 32 - 255.
Naturally, at an encryption and decoding the program should zaprashi-vat at the user a key.

I hope you do not write all code  bed-sheets without indents. Pay to this attention.
It was necessary to format for you.
On the code. This sort of utilities are convenient for developing through TDD.  you at first write test set.
You drive in into them constants which undoubted know or they came from . And further you write the code to the such
In the image that these tests became an invariant in relation to your code. Operation with files it is necessary temporarily
To throw out. And to add it in the latest stage when modular tests entered into green sector. After
It the software is ready.
Why it is important? I will explain. If you somewhere bungled with  an output or input in a file - at you in the code
There will be a complex error and it will be difficult to you to understand on what phase it arose. In decoding or
In file reading.

7

Re: The cipher of Gronsfelda

Here even I would run into a stupor...