Skip to content

Instantly share code, notes, and snippets.

@Jacajack
Created January 16, 2017 00:41
Show Gist options
  • Save Jacajack/7005b9b531ad0f1b412ffae15e987e5d to your computer and use it in GitHub Desktop.
Save Jacajack/7005b9b531ad0f1b412ffae15e987e5d to your computer and use it in GitHub Desktop.
Super simple LFSR cipher in C
#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