Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- #include <string.h>
- int key;
- int convert(string x);
- void digit(string y);
- int main(int argc, string argv[])
- {
- printf("argv: %s\n", argv[1]);
- //checks if positive digits
- digit(argv[1]);
- if (argc != 2)
- {
- printf("Usage: ./caesar key");
- }
- else
- {
- key = convert(argv[1]);
- printf("Key: %i\n", key);
- string plain = get_string("Gimme plaintext: ");
- printf("plaintext: %s\n", plain);
- printf("ciphertext: ");
- for (int i = 0, len = strlen(plain) ; i < len; i++)
- {
- //QUESTION HERE!!!
- char cypher = (plain[i] + key) % 26;
- printf("%c", cypher);
- }
- printf("\n");
- }
- }
- //is digit?
- void digit(string y)
- {
- int len = strlen(y);
- printf("Usage: ");
- for (int i = 0; i < len; i++)
- if (y[i] >= 48 && y[i] <= 57)
- {
- printf("%c", y[i]);
- }
- else
- {
- printf("./caesar key\n");
- exit(0);
- }
- printf("\n");
- }
- // convert string into digits, or my atoi
- int convert(string x)
- {
- int res = 0;
- int len = strlen(x);
- printf("String: %s\n", x);
- printf("Len: %i\n", len);
- for (int j = 0 ; j < len ; j++)
- {
- res = res * 10 + x[j] - '0';
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement