The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Vigenere
Discuss Vigenere in the C Programming forum on Dev Shed. Vigenere C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 2nd, 2012, 09:35 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 29 m 20 sec
Reputation Power: 0
|
|
Vigenere
Hello friends,
I need a help for my programming. When I get the Key, I did nothing appears on the screen.
Thanks !
Code:
#define CL 10 // Key length
#define TX 110 //Word length
#include<stdio.h>
#include<string.h> //for strlen()
int main()
{
char txt [TX]={0};
char cle[CL]={0};
char txtkrypt[TX]={0};
int a,b,i,j,s; //variable of encryption
char grille [26][26]= {"abcdefghijklmnopqrstuvwxyz"};
printf("enter the text : ");
scanf("%s",txt);
printf("enter the key :");
scanf("%s",cle);
a=0;
b=0;
s=strlen(cle);
do{
for(i=0;i<26;i++){ //incrementation of i
if(txt[a]==grille[0][i]){
for(j=0;j<26;j++){ //incrementation of j
if(cle[b]==grille[j][0])
txtkrypt[a]=grille[j][i];
}
}
}
a++; //incrementation of a (word character )
b++; //incrementation of b (character of key)
if(b==s)b=0;
}
while(txt[a]!='\0'); //as a txt is not the end
printf("text crypt:\n%s\n\n\n\n",txtkrypt);
return 0;
}
|

December 2nd, 2012, 12:02 PM
|
 |
Contributed User
|
|
|
|
|
Nobody will care about your post, since your code is all on one line.
|

December 2nd, 2012, 12:02 PM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: San Francisco Bay
|
|
|
Please reformat your code so that it isn't all on a single line.
|

December 2nd, 2012, 12:22 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 29 m 20 sec
Reputation Power: 0
|
|
|
Done! Sorry....
|

December 2nd, 2012, 02:14 PM
|
 |
Contributed User
|
|
|
|
Indented code should look something like this.
Code:
#define CL 10 // Key length
#define TX 110 //Word length
#include<stdio.h>
#include<string.h> //for strlen()
int main()
{
char txt[TX] = { 0 };
char cle[CL] = { 0 };
char txtkrypt[TX] = { 0 };
int a, b, i, j, s; //variable of encryption
char grille[26][26] = { "abcdefghijklmnopqrstuvwxyz" };
printf("enter the text : ");
scanf("%s", txt);
printf("enter the key :");
scanf("%s", cle);
a = 0;
b = 0;
s = strlen(cle);
do {
for (i = 0; i < 26; i++) { //incrementation of i
if (txt[a] == grille[0][i]) {
for (j = 0; j < 26; j++) { //incrementation of j
if (cle[b] == grille[j][0])
txtkrypt[a] = grille[j][i];
}
}
}
a++; //incrementation of a (word character )
b++; //incrementation of b (character of key)
if (b == s)
b = 0;
}
while (txt[a] != '\0'); //as a txt is not the end
printf("text crypt:\n%s\n\n\n\n", txtkrypt);
return 0;
}
Some problems.
1. char grille [26][26]= {"abcdefghijklmnopqrstuvwxyz"};
This only initialises the first ROW of your grille. All the other rows are full of \0.
2. scanf("%s", txt);
OK if all you input is "hello"
But if you try to input "The quick brown fox", then you're going to be disappointed.
|

December 3rd, 2012, 01:18 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 29 m 20 sec
Reputation Power: 0
|
|
|
Vigenere
Thanks ! But how can I fix the problem ??
I try without the second grille, but for me the second grille is necessary no ?
Code:
#define CL 10 // Key length
#define TX 110 //Word length
#include<stdio.h>
#include<string.h> //for strlen()
int main()
{
char txt[TX] = { 0 };
char cle[CL] = { 0 };
char txtkrypt[TX] = { 0 };
int a, b, i, j, s; //variable of encryption
char grille[26] = { "abcdefghijklmnopqrstuvwxyz" };
printf("enter the text : ");
scanf("%s", txt);
printf("enter the key :");
scanf("%s", cle);
a = 0;
b = 0;
s = strlen(cle);
do {
for (i = 0; i < 26; i++) { //incrementation of i
if (txt[a] == grille[0]) {
for (j = 0; j < 26; j++) { //incrementation of j
if (cle[b] == grille[j])
txtkrypt[a] = grille[j];
}
}
}
a++; //incrementation of a (word character )
b++; //incrementation of b (character of key)
if (b == s)
b = 0;
}
while (txt[a] != '\0'); //as a txt is not the end
printf("text crypt:\n%s\n\n\n\n", txtkrypt);
return 0;
}
|

December 4th, 2012, 12:35 AM
|
 |
Contributed User
|
|
|
|
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|