Guest User

cs50 badcode

a guest
Jan 25th, 2023
1,614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6.  
  7. int main(int argc, string argv[])
  8. {
  9. string arr[] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
  10. int key = atoi(argv[1]);
  11. string plaintext = get_string("plaintext: ");
  12. char cpystr[64];
  13. for (int i = 0; i < sizeof(plaintext); i++)
  14. {
  15. strncpy(cpystr, plaintext, 64);
  16. }
  17. int h = 0;
  18. for (h = 0; cpystr[h]!='\0'; h++)
  19. {
  20. if(cpystr[h] >= 'a' && cpystr[h] <= 'z')
  21. {
  22. cpystr[h] = cpystr[h] - 32;
  23. }
  24. }
  25. char cipher[64];
  26. printf("ciphertext: ");
  27. for (int i = 0; i < strlen(cpystr); i++)
  28. {
  29. cipher[i] = strcmp(&cpystr[i], arr[0]) + key;
  30. int val = cipher[i];
  31. printf("%s", arr[val]);
  32. }
  33. printf("\n");
  34. }
Advertisement
Add Comment
Please, Sign In to add comment