waltermilner

Untitled

Mar 28th, 2021
568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. int main (void)
  7. {
  8.   char * test="This is a secret message"; // test input
  9.   const int SHIFT=9; // the shift
  10.   char * coded = malloc(strlen(test)+1); // get memory of same size
  11.   for (int i=0; i<strlen(test); i++) // go through input
  12.     *(coded+i)=*(test+i) + SHIFT; // write to output, + SHIFT
  13.   *(coded+strlen(test))=0; // make sure have 0 at the end
  14.   printf("Coded: %s\n",coded); // display it
  15. // Result: Coded: ]qr|)r|)j)|nl{n})vn||jpn
  16.  
  17.   return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment