C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 2nd, 2012, 09:35 AM
Jeanjean Jeanjean is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 Jeanjean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 20 sec
Reputation Power: 0
Unhappy 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;
}

Reply With Quote
  #2  
Old December 2nd, 2012, 12:02 PM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,839 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 18 h 45 m 47 sec
Reputation Power: 1774
Nobody will care about your post, since your code is all on one line.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #3  
Old December 2nd, 2012, 12:02 PM
Lux Perpetua Lux Perpetua is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: San Francisco Bay
Posts: 1,936 Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level)Lux Perpetua User rank is General 5th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 h 12 m 42 sec
Reputation Power: 1312
Please reformat your code so that it isn't all on a single line.

Reply With Quote
  #4  
Old December 2nd, 2012, 12:22 PM
Jeanjean Jeanjean is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 Jeanjean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 20 sec
Reputation Power: 0
Done! Sorry....

Reply With Quote
  #5  
Old December 2nd, 2012, 02:14 PM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,839 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 18 h 45 m 47 sec
Reputation Power: 1774
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.

Reply With Quote
  #6  
Old December 3rd, 2012, 01:18 PM
Jeanjean Jeanjean is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 Jeanjean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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;
}

Reply With Quote
  #7  
Old December 4th, 2012, 12:35 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,839 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 18 h 45 m 47 sec
Reputation Power: 1774
> for (i = 0; i < 26; i++) { //incrementation of i
> if (txt[a] == grille[0]) {
If txt[a] == grille[0] is false the first time around, then doing it a further 25 times isn't going to help.

http://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Vigenere

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap