jordan40417669

key

Jan 9th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7.  
  8.  
  9. char keyinput[127];
  10. int defaultkey;
  11. int bit;
  12. int k;
  13.  
  14.  
  15. printf("Enter Your Key. Number between 1 & 127.\n");
  16. fgets(keyinput, 127, stdin);
  17. int usekey = atoi(keyinput);
  18. printf("%d\n", usekey);
  19.  
  20. if(usekey >= 1 && usekey < 127)
  21.     {
  22.     printf("The Key You Are Using Is %d\n", usekey);
  23.     }
  24.     else if (usekey > 127)
  25.     {
  26.     usekey = 101;
  27.     printf("Number Entered For Key Is To Big. Using Defaultkey %d\n", usekey);
  28.     }
  29.     else
  30.     {
  31.     usekey = 101;
  32.     printf("No Key Was Entered. Using Default Key %d\n", usekey);
  33.     }
  34.    //now turn this number into binary
  35.    
  36.    for (bit = 7; bit >= 0; bit--)
  37.   {
  38.     k = usekey >> bit;
  39.  
  40.     if (k & 1)
  41.       printf("1");
  42.     else
  43.       printf("0");
  44.   }
  45.  
  46.   printf("\n");
  47.  
  48.   return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment