Thread: Vigenere

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    3

    Angry Vigenere

    I just created a new file for C++ Source, not C/C++ Header. here my code doesn't work. i appreciate your help. thanks

    #include <stdio.h>
    #include <ctype.h>

    void
    PrintUsage()
    {
    printf("Usage: vignere [ -e | -d ] key \n");
    }

    main(int argc, char** argv)
    {
    char* key;
    char next, vignere;
    int keylength, vigindex, i = 0;
    if(argc < 3) { PrintUsage(); exit(1);}

    if((keylength=strlen(argv[2])) > 26 || keylength <= 0)
    { printf("Key must be between 1 - 26 characters\n"), exit(1); }
    key = argv[2];

    if(strcmp(argv[1], "-d") == 0)
    {
    while( ((next = toupper(getchar())) != EOF))
    {
    if(next >= 64 && next <= 91)
    {
    vigindex = (int)(toupper(key[i]) - 'A');

    if((int)(next-'A') >= vigindex)
    {vignere = (char)(next - vigindex);}
    else
    {vignere = (char)((char)('Z' - vigindex - 'A' + 1) + (char)next); }
    next = toupper(vignere);
    i = (i+1) % keylength;
    printf("%c", next);
    }
    }
    }
    else if (strcmp(argv[1], "-e") == 0)
    {
    while( ((next = tolower(getchar())) != EOF))
    {
    if(next >= 97 && next <= 122)
    {
    vigindex = ((next-'a') + (tolower(key[i] - 'a'))) % 26;
    i = (i+1) % keylength;
    next = 'a' + vigindex;
    printf("%c", next);
    }
    }
    }
    }

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    >here my code doesn't work.

    Well... would you care to tell us what it should do and what is the result you get ? What would you like it to do ? Does it compile ? Does it link ? Does it produce the right output ?

    I can program, but I'm still a newbie at reading minds

    Hint: When posting a large chunk of code, use the [ CODE ] tags.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vigenere Cipher decryption help needed
    By magic101 in forum C Programming
    Replies: 2
    Last Post: 02-07-2009, 07:25 PM
  2. Crashing Vigenere Cipher program
    By ultrabot90 in forum C++ Programming
    Replies: 15
    Last Post: 09-21-2007, 05:41 PM
  3. Could this make Vignere more secure?
    By kinghajj in forum C# Programming
    Replies: 8
    Last Post: 03-30-2005, 11:19 PM
  4. Vigenere Encryption
    By vasanth in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2002, 02:53 PM
  5. Vigenere Decipher/Encipher
    By Xander in forum C++ Programming
    Replies: 5
    Last Post: 02-15-2002, 09:24 AM