You're here: Snippet Directory » C/C++ (495)
Language:

Keyfile Creator for BitMix64 snippet

Language: English
Programming Language: C
Published by: ctiger [not registered]
Last Update: 5/15/2006
Views: 119

Description

Creates Key files for the BitMix64 algorithm. NEVER USE OTHER FILES AS KEYS, BECAUSE YOU PROBABLY WON'T BE ABLE TO DECRYPT YOUR FILES AGAIN!

Code

1 ///////////////////////////////////////////////////////////// 2 // General information 3 // 4 // Author: ctiger 5 // 6 // Purpose: Creates key files for BitMix64 algorithm 7 // 8 // Uses: C Runtime Library 9 // 10 // Designed for and tested on: 11 // Windows 95/98 12 13 #include <io.h> 14 #include <stdio.h> 15 #include <stdlib.h> 16 #include <time.h> 17 18 ///////////////////////////////////////////////////////////// 19 // This function takes a file handle previously opened by 20 // _open(). 1024 randomly created key characters will be 21 // written to it. The file handle must be opened in binary 22 // write mode (_O_WRONLY | _O_BINARY). 23 // 24 void BM64MakeKey(int hKey) 25 { 26 // assure proper file size and output position 27 _lseek(hKey, 0, SEEK_SET); 28 _chsize(hKey, 0); 29 30 unsigned char shifts[7] = {0x30, 0x50, 0x70, 0x90, 0xb0, 0xd0, 0xf0}; 31 unsigned char key[1024]; 32 33 // the random numbers should be as randomly picked as possible 34 srand(time(0)); 35 srand(rand() * rand()); 36 srand(time(0) + clock() * rand()); 37 38 for (int n = 0; n < 1024; ++n) 39 key[n] = (rand() % 16) | shifts[rand() % 7]; 40 41 _write(hKey, &key[0], 1024); 42 } 43 44 ////////////////////////////////// 45 // sample function to show usage 46 // 47 48 #include <process.h> // needed for system() routine 49 50 int main(int argc, char *argv[]) 51 { 52 if (argc < 2) return -1; 53 54 int keyfile = _open(argv[1], _O_WRONLY | _O_BINARY); 55 BM64MakeKey(keyfile); 56 _close(keyfile); 57 58 char path[260]; 59 sprintf(&path[0], "TYPE %s", argv[1]); 60 return system(&path[0]); 61 } 62

No comments avaiable

Add a comment

Name *  

Email (won't be displayed) *    

Website  

Comment *  

Sicherheitscode Security Code *    

RSS