0

i need little help completing Hail, Caesar! trying to complete it from last 4 days.

This is my code so far:

include

include

include

include

include

int main(int argc, string argv[]) { string key = argv1; if (argc != 2) {
printf("Give me a key also\n"); return 1; }

int k = atoi(key) % 26;

//printf("Give me the Plain Text: \n");
//string pl = GetString();

//int pl = 'A';

int c = ('A' + k) % 26;


printf("is %c is %d\n", c, c);

}

I was watching Zamyla's walk through and she was able to get the ASCI Character and number! But i am only getting the numbers, like i tried to execute: ./ceaser 2 and the output was this:

enter image description here

Can anyone please tell me why am i getting no character in the terminal?

1
  • Still stuck!! need more help: This is my recent code: int main(int argc, string argv[]) { string key = argv[1]; if (argc != 2) { printf("Give me a key also\n"); return 1; } int k = atoi(key); printf("Give me the Plain Text: \n"); string p = GetString(); for (int c = ('A' + k), i = 0, n = strlen(p); i < n; i++) { printf("%c\n", p[i + c]); } } From the recent answers i am able to print the ASCII characters but not sure how to implement it with string, need help... Commented May 11, 2016 at 23:24

3 Answers 3

1

OK so a quick look through your code and first of all I think I should remind you that in your second last line, trying to wrap around from z to a using %26 will only work if you are not using ASCII numbers which you are. OK back to your question, your condition for checking argc seems to only check for two arguments and return... have you considered how many you actually need? And I see no code for picking up the text to be encrypted like you did for the key.... hope this helps :)

3
  • Thanks for the help, Commented May 11, 2016 at 23:20
  • Yes removing %26 worked the i wanted, but now i am stuck how to implement that with the string, Commented May 11, 2016 at 23:21
  • This is my code now: int main(int argc, string argv[]) { string key = argv[1]; if (argc != 2) { printf("Give me a key also\n"); return 1; } int k = atoi(key); printf("Give me the Plain Text: \n"); string p = GetString(); for (int c = ('A' + k), i = 0, n = strlen(p); i < n; i++) { printf("%c\n", p[i + c]); } } I want to implement that with the string but i am stuck, not sure how to! can you please help me? Commented May 11, 2016 at 23:22
1

I guess you are only trying to print ASCII value and its corresponding letter and not the PSET caeser cypher per se. In that case the subject line is misleading.

Coming to your code, did you calculate what value does c holds while trying to print its value. After calculating look up at the ASCII table what that value corresponds to. Can that character be represented using any of the keyboard characters?

I think you'll get your answer if you evaluate the above pointers.

2
  • Yes for now i am checking with ASCII, as it's in the Zamyla's video and i think this is the way to start? Commented May 11, 2016 at 22:24
  • In the above code, if for e.g. k = 2, then c comes out to be 67 % 26 = 15. In the ASCII table this value corresponds to (shift in), and not any alphabets. Hint: Modulo Operator (%) in this case will only work if performed on number less than or equal to 26 (and not 65 as was the case above).
    – ABor
    Commented May 12, 2016 at 3:21
0

hope u got the solution...did u? because i am not sure about your for loop.... try keeping the key as you get it but first take the ascii characters back to normal 1-26 alphabet, apply the key, then change them back...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .