Created
January 16, 2017 00:41
-
-
Save Jacajack/7005b9b531ad0f1b412ffae15e987e5d to your computer and use it in GitHub Desktop.
Super simple LFSR cipher in C
This file contains 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 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 sr & 0xff; | |
} | |
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