Files
WjCryptLib/projects/Rc4Output/Rc4Output.c
zebra f75d43bb19 Version 2.0.0
* Added AES and AES-CTR modules. AES-CTR conforms to the same counter
mode used with AES in *OpenSSL*.
* All algorithms now work on Big-Endian architectures.
* Now uses CMake for building rather than make files and Visual Studio
projects. CMake will generate whatever system is required.
* Input function parameters are now marked `const`
* File names have been changed to have the prefix `CryptLib_` rather
than `Lib`.
* Various formatting changes to the files.
2017-12-02 00:16:32 +11:00

92 lines
2.9 KiB
C

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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 <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "CryptLib_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 <Key> <NumBytes> [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<chunk; i++ )
{
printf( "%2.2x", buffer[i] );
}
}
printf( "\n" );
return 0;
}