Advertisement
AbstractBeliefs

Untitled

Feb 22nd, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. void decrypt(uint16_t cipher[], char clear[], int ct_len){
  5.     // Decrypt a XORed string. ciphertext is a uint16_t of
  6.     // length n (from ct_len), and cleartext is a char of
  7.     // length 2n + 1 (2 chars per 16bits, plus \0) 
  8.  
  9.     for (int i = 0; i < ct_len; i++){
  10.         uint16_t decpair = cipher[i] ^ 31337;
  11.         // Take the dec'd pair, mask, shift, save
  12.         clear[(2*i)] = (char) ((decpair & 0xF0) >> 8);
  13.         clear[(2*i)+1] = (char) ((decpair & 0x0F) >> 0);
  14.     }
  15.  
  16.     // Make the last char in the cleartext a nullchar.
  17.     clear[(2*ct_len)] = '\0';
  18.     return;
  19. }
  20.  
  21. void main(){
  22.     uint16_t ciphertext[] = {
  23.         15643,
  24.         6913,
  25.         6916,
  26.         23040,
  27.         2377,
  28.         6985,
  29.         6408,
  30.         3657,
  31.         5638,
  32.         3084,
  33.         2119,
  34.         15910,
  35.         23079,
  36.         13629,
  37.         23101,
  38.         10300,
  39.         10557,
  40.         23073,
  41.         13092,
  42.         23369
  43.     };
  44.  
  45.     int cipherlen = 20;
  46.     char cleartext[41];
  47.  
  48.     decrypt(ciphertext, cleartext, cipherlen);
  49.  
  50.     printf(cleartext);
  51.     getchar();
  52.     return;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement