ceaser cypher

hey so i need to make a ceased cypher program where you input the coded message and output the cyphered version. i have this code and it compiles with no issues but it won't do anything. not sure why. any help would be greatly appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <cstring>
#include <cctype>

using namespace std;

void  encrypt (int, char[]);
void  decrypt (int, char[]);
char transform (char, int);

int main(int argc, char *argv[]) {
    int n,key;
    
    
    if(argc != 4)
    {
        cout<<"Expected an integer and a string "<<endl;
        
        return 0;
    }
    
    // Print the original message supplied by the user
    cout<<"Print original message: "<<endl;
    cout<<argv[3]<<endl;
    cout<<"New message: "<<endl;
    
    // Convert the operation number and the numeric key to an integer
    n=atoi(argv[1]);
    key=atoi( argv[2]);
    if(n==0)
        encrypt(key,argv[-3]);
    else
        decrypt(key,argv[-3]);
    printf ( "Press any key to continue . . ." );
    
    return 0;
}

char transform(char ch, int key)
{

    char alpha[] = "abcdefghijklmnopqrstuvwxyz";
    char low_case = tolower(ch);
    int i=0;
    while((low_case != alpha[i]) && (i < 26))
        i++;
    if (i > 25)
        return ch;
    int new_key = key % 25;
    if (new_key + i > 25)
    {
        return alpha[(new_key + i) % 25];
    }
    else
    {
        return alpha[new_key + i];
    }
}

void encrypt(int key, char mess[])
{int i=0;
    
    while(mess[i]!='\0')
        cout<<transform(mess[i++],key);
    cout<<endl;
    return;
}


void decrypt(int key, char mess[])
{int i=0;
    
    while(mess[i]!='\0')
        cout<<transform(mess[i++],-key);
    cout<<endl;
    return;
}
What is argv[-3] ?
What is argv[-3] ?


What is a segmentation fault, Alex.
Topic archived. No new replies allowed.