//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Rc4String // // Outputs bytes from an RC4 stream. Key is taken from command line. Bytes are output as hex // // This is free and unencumbered software released into the public domain - June 2013 waterjuice.org //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // IMPORTS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include "WjCryptLib_Rc4.h" //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // DEFINITIONS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #ifndef __min #define __min( x, y ) (((x) < (y))?(x):(y)) #endif //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // CONSTANTS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #define BUFFER_SIZE 1024 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // main // // Program entry point //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int main ( int ArgC, char** ArgV ) { char* string; uint32_t numBytes; uint32_t i; uint8_t buffer [BUFFER_SIZE]; uint32_t amountLeft; uint32_t chunk; Rc4Context rc4 = {0}; uint32_t dropN = 0; if( 3 != ArgC && 4 != ArgC ) { printf( "Syntax\n" " Rc4Output [DropN]\n" ); return 1; } string = ArgV[1]; numBytes = atoi( ArgV[2] ); if( 4 == ArgC ) { dropN = atoi( ArgV[3] ); } Rc4Initialise( &rc4, string, (uint32_t)strlen(string), dropN ); amountLeft = numBytes; while( amountLeft > 0 ) { chunk = __min( amountLeft, BUFFER_SIZE ); Rc4Output( &rc4, buffer, chunk ); amountLeft -= chunk; for( i=0; i