P
Piotr Turkowski
Hi!
Here you can get some notes about Vigenere Cipher:
http://raphael.math.uic.edu/~jeremy/crypt/vignere.html
Here's whole code of my program, function stats() is in polish, so you
can omit it. The problem is that the encrypting function is not working
correctly, so I didn't write decryptying function. Plz, can you help me
with both issues?
#include <stdio.h>
#define IN 1 /* wewn¹trz s³owa */
#define OUT 0 /* poza s³owem */
/* Vigenere Cipher */
/* deklaracje fuknkcji uzytych w programie */
int wypelnij_male(char tab[][]);
int wypelnij_duze(char tab[][]);
char haslo(int ii, char pass[]);
void koduj_numer(char c);
void szyfruj();
void deszyfruj();
void stats();
main() {
/* menu programu */
int menu;
for(;
{
printf("\n");
printf("1. Szyfrowanie tekstu.\n");
printf("2. Deszyfrowanie tekstu.\n");
printf("3. Statystyka.\n");
printf("4. Zakonczenie programu.\n");
scanf("%d", &menu);
switch(menu) {
case 1: szyfruj(); break;
case 2: deszyfruj();
case 3: stats();
case 4: return;
default: return;
}
}
}
void szyfruj(){
int ii, c, i, s;
char pass[]={0};
char MALE[26][26]={0};
char DUZE[26][26]={0};
wypelnij_male(MALE);
wypelnij_duze(DUZE);
printf("Podaj haslo: ");
scanf("%s\0", &pass);
getchar();
printf("Podaj tekst do zaszyfrowania:\n");
for (ii = 0; (c = getchar()) != '\n'; ++ii) {
if (c >= 'a' && c <= 'z') {
putchar(MALE[c - 'a'][haslo(ii, pass) - 'a']);
}
else if (c >= 'A' && c <= 'Z') {
putchar(DUZE[c - 'A'][haslo(ii, pass) - 'A']);
}
else koduj_numer(c);
}
putchar('\n');
getchar();
system("cls");
/*
!!!!!!!!!!!!!!!!!!!!!
tu czyszczenie ekranu
!!!!!!!!!!!!!!!!!!!!!
*/
}
/* Funkcja wypelniajaca tablice dwuwymiarowa malymi literami alfabetu */
int wypelnij_male(char tab[26][26]) {
int xx, yy;
for (yy = 0; yy <= 25; yy++)
for (xx = 0; xx <= 25; xx++)
tab[yy][xx]=('a' + ((yy+xx) % 26));
}
/* Funckja wypelniajaca tablice dwuwymiarowa wiekimi literami alfabetu */
int wypelnij_duze(char tab[26][26]) {
int xx, yy;
for (yy = 0; yy <= 25; yy++)
for (xx = 0; xx <= 25; xx++)
tab[yy][xx]='A' + ((yy+xx) % 26);
}
/* Fukncja zwracajaca aktualna litere w hasle */
char haslo(int ii, char pass[]) {
int k;
k = ii % (sizeof(pass));
return pass[k];
}
void koduj_numer(char c){putchar(c);}
void deszyfruj(){}
void stats() {
int c, state, num_lines, num_words, num_chars, num_let, num_digit,
num_spec;
state = OUT;
num_lines = num_words = num_chars = num_let = num_digit = num_spec = 0;
while ((c = getchar()) != '\t') {
++num_chars;
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
c = 1;
num_let = num_let + c;
}
if (c >= '0' && c <= '9') {
c = 1;
num_digit = num_digit + c;
}
if (c == '\n')
++num_lines;
if (c == ' ' || c == '\n' || c == '\t')
state = OUT;
else if (state == OUT) {
state = IN;
++num_words;
}
}
num_spec = num_chars - (num_let + num_digit);
printf("Statystyki tekstu:\n\n");
printf("\tIlosc wszystkich znakow: %d\n", num_chars);
printf("\tIlosc wszyskich slow: %d\n", num_words);
printf("\tIlosc liter: %d", num_let);
printf("\tIlosc cyfr: %d", num_digit);
printf("\tIlosc znakow specjalnych: %d", num_spec);
getchar();
getchar();
system("cls");
}
Here you can get some notes about Vigenere Cipher:
http://raphael.math.uic.edu/~jeremy/crypt/vignere.html
Here's whole code of my program, function stats() is in polish, so you
can omit it. The problem is that the encrypting function is not working
correctly, so I didn't write decryptying function. Plz, can you help me
with both issues?
#include <stdio.h>
#define IN 1 /* wewn¹trz s³owa */
#define OUT 0 /* poza s³owem */
/* Vigenere Cipher */
/* deklaracje fuknkcji uzytych w programie */
int wypelnij_male(char tab[][]);
int wypelnij_duze(char tab[][]);
char haslo(int ii, char pass[]);
void koduj_numer(char c);
void szyfruj();
void deszyfruj();
void stats();
main() {
/* menu programu */
int menu;
for(;
printf("\n");
printf("1. Szyfrowanie tekstu.\n");
printf("2. Deszyfrowanie tekstu.\n");
printf("3. Statystyka.\n");
printf("4. Zakonczenie programu.\n");
scanf("%d", &menu);
switch(menu) {
case 1: szyfruj(); break;
case 2: deszyfruj();
case 3: stats();
case 4: return;
default: return;
}
}
}
void szyfruj(){
int ii, c, i, s;
char pass[]={0};
char MALE[26][26]={0};
char DUZE[26][26]={0};
wypelnij_male(MALE);
wypelnij_duze(DUZE);
printf("Podaj haslo: ");
scanf("%s\0", &pass);
getchar();
printf("Podaj tekst do zaszyfrowania:\n");
for (ii = 0; (c = getchar()) != '\n'; ++ii) {
if (c >= 'a' && c <= 'z') {
putchar(MALE[c - 'a'][haslo(ii, pass) - 'a']);
}
else if (c >= 'A' && c <= 'Z') {
putchar(DUZE[c - 'A'][haslo(ii, pass) - 'A']);
}
else koduj_numer(c);
}
putchar('\n');
getchar();
system("cls");
/*
!!!!!!!!!!!!!!!!!!!!!
tu czyszczenie ekranu
!!!!!!!!!!!!!!!!!!!!!
*/
}
/* Funkcja wypelniajaca tablice dwuwymiarowa malymi literami alfabetu */
int wypelnij_male(char tab[26][26]) {
int xx, yy;
for (yy = 0; yy <= 25; yy++)
for (xx = 0; xx <= 25; xx++)
tab[yy][xx]=('a' + ((yy+xx) % 26));
}
/* Funckja wypelniajaca tablice dwuwymiarowa wiekimi literami alfabetu */
int wypelnij_duze(char tab[26][26]) {
int xx, yy;
for (yy = 0; yy <= 25; yy++)
for (xx = 0; xx <= 25; xx++)
tab[yy][xx]='A' + ((yy+xx) % 26);
}
/* Fukncja zwracajaca aktualna litere w hasle */
char haslo(int ii, char pass[]) {
int k;
k = ii % (sizeof(pass));
return pass[k];
}
void koduj_numer(char c){putchar(c);}
void deszyfruj(){}
void stats() {
int c, state, num_lines, num_words, num_chars, num_let, num_digit,
num_spec;
state = OUT;
num_lines = num_words = num_chars = num_let = num_digit = num_spec = 0;
while ((c = getchar()) != '\t') {
++num_chars;
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
c = 1;
num_let = num_let + c;
}
if (c >= '0' && c <= '9') {
c = 1;
num_digit = num_digit + c;
}
if (c == '\n')
++num_lines;
if (c == ' ' || c == '\n' || c == '\t')
state = OUT;
else if (state == OUT) {
state = IN;
++num_words;
}
}
num_spec = num_chars - (num_let + num_digit);
printf("Statystyki tekstu:\n\n");
printf("\tIlosc wszystkich znakow: %d\n", num_chars);
printf("\tIlosc wszyskich slow: %d\n", num_words);
printf("\tIlosc liter: %d", num_let);
printf("\tIlosc cyfr: %d", num_digit);
printf("\tIlosc znakow specjalnych: %d", num_spec);
getchar();
getchar();
system("cls");
}