Last active
July 27, 2017 01:06
-
-
Save Jacajack/6203526f2ee92991872ff767ebdf6fa0 to your computer and use it in GitHub Desktop.
Simple LFSR cipher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <inttypes.h> | |
uint64_t sr; | |
uint8_t *srb = (uint8_t*) &sr; | |
uint8_t shift( ) | |
{ | |
//Taps at 64, 63, 61, 60 | |
uint8_t shiftin = 0; | |
shiftin ^= ( ( sr & ( 1ULL << 0 ) ) >> 0 ); | |
shiftin ^= ( ( sr & ( 1ULL << 1 ) ) >> 1 ); | |
shiftin ^= ( ( sr & ( 1ULL << 60 ) ) >> 60 ); | |
shiftin ^= ( ( sr & ( 1ULL << 59 ) ) >> 59 ); | |
sr = ( sr << 1 ) | ( shiftin ); | |
return srb[0] ^ srb[1] ^ srb[2] ^ srb[3] ^ srb[4] ^ srb[5] ^ srb[6] ^ srb[7]; | |
} | |
int main( int argc, char **argv ) | |
{ | |
char c; | |
if ( argc < 2 ) | |
{ | |
printf( "Please specify cipher integer!\n" ); | |
return 1; | |
} | |
sr = atoll( argv[1] ); | |
while ( ( c = getchar( ) ) != EOF ) | |
putchar( c ^ shift( ) ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment