All pastes #2068744 Raw Edit

jamesjedimaster

public text v1 · immutable
#2068744 ·published 2011-05-25 02:24 UTC
rendered paste body
jcr@tuuktux:~$ cat progs/rot13.c 
#include <stdio.h>
#include <string.h>

int bintodec(int binnum)
{
 int total = 0;
 int power = 1;

 while(binnum > 0)
 {
  total += binnum % 10 * power;
  binnum = binnum / 10;
  power = power * 2;
 }

 return total;
} 

char rot13(int onechar)
{
 char c = onechar;

 if(c < 110) c = c + 13;
 else c = c - 13;

 return c;
}

int main(int argc, char *argv[])
{
 char str[]="1101000 100000 1100101 1110010 1101110 1111001 1111001 1101100 100000 1101110 1100101 1110010 100000 1101110 100000 1110100 1110010 1110010 1111000";
 char *token;

 token = strtok(str, " ");
 do
 {
  printf("%s\t%d\t%c\t%c\n", token, bintodec(atoi(token)), bintodec(atoi(token)), rot13(bintodec(atoi(token))));
  token = strtok(NULL, " ");
 }while(token != NULL);
}