440,929 Members | 1,245 Online
Need help? Post your question and get tips & solutions from a community of 440,929 IT Pros & Developers. It's quick & easy.

# Basic encryption

 P: n/a I'm looking to do my own basic encryption. I've been tyring to do a concept such as: I pass this function the string, key and number of rounds I want to do the encryption. because im round shifting the bits the decryption doesn't work.. :P Am I going about this all wrong or does anybody know an easier way (besides getting an open source algo class such as Crypto++) I'm super new to fooling with the bits/encryption for(;num of rounds;) { char ^ Key; Round bit shift; } Jul 19 '05 #1
6 Replies

 P: n/a "Richard" wrote in message news:3b**************************@posting.google.c om... | I'm looking to do my own basic encryption. I've been tyring to do a | concept such as: | | I pass this function the string, key and number of rounds I want to do | the encryption. because im round shifting the bits the decryption | doesn't work.. :P | Am I going about this all wrong or does anybody know an easier way | (besides getting an open source algo class such as Crypto++) | | I'm super new to fooling with the bits/encryption | | for(;num of rounds;) | { | char ^ Key; | Round bit shift; | } What type of encryption you want to implement is not really clear to me. Just a few comments I can throw in: Watch that the bit-shift operators (<< and >>) actually lose data: they shift bits, and do not roll them. To implement rolling on a e.g. 32-bit value, you can use something like: *dst = (*src << nbits) | (*src >> (32-nbits) ); Where *dst and *src shall be 32-bit unsigned integers, and nbits must be in [1..31]. Not sure if it helps, but a 'simple' encryption source code can be found at: http://ivan.vecerina.com/code/coopfish/ . (implements the blowfish algorithm in a C++ fashion). hth-Ivan -- http://ivan.vecerina.com Jul 19 '05 #2

 P: n/a sh*****@hotmail.com (Richard) wrote in message news:<3b**************************@posting.google. com>... I'm looking to do my own basic encryption. I've been tyring to do a concept such as: I pass this function the string, key and number of rounds I want to do the encryption. because im round shifting the bits the decryption doesn't work.. :P Am I going about this all wrong or does anybody know an easier way (besides getting an open source algo class such as Crypto++) I'm super new to fooling with the bits/encryption for(;num of rounds;) { char ^ Key; Round bit shift; } I just made a similar program, as vehicle to use to (try) to learn cpp). The code is zipped up at: http://home.bellsouth.net/p/PWP-brightwave To compile it, include all the CPP files into a project then build it. int main() is in j_crypt.cpp. Or...you can drop a file on the exe file if you don't want to compile it yourself. This code will *not* modify/overwrite any files...it always gives them a new name. Anyway...this is what I came up with. slicerclass is a PRNG that can be used stand-alone, once initialized, the member function get_rand() returns a "random" unsigned long int. My prog may be a little more complicated than what you have in mind. I made use of a custom file-format that carries the original filename (encrypted) and a hash-value for the original file (also encrypted), so that authentication can be performed. I do not present this as model code, or as an example of learned cryptography. It happens to be where I stand in late 2003 on the learning curve. What this crypto will do is...take any file (even one filled with null bytes) and generate a stream of data indistinguishable from "random" that contains the file info. Having a copy of both the plain and cypher-text won't help an attacker get the password. Successfully unencrypted files are authenticated. There is an inbuilt mechanism designed to make a dictionary attack difficult. cheers. Jul 19 '05 #3

 P: n/a Thanks guys, Ya i took into consideration when you shift you loose bits. I was justORing it with 0x80 for char to test if bit was 1/0 so i could tack it on the end i was shifting into. I should be able to get it right by trial and error. sh*****@hotmail.com (Richard) wrote in message news:<3b**************************@posting.google. com>... I'm looking to do my own basic encryption. I've been tyring to do a concept such as: I pass this function the string, key and number of rounds I want to do the encryption. because im round shifting the bits the decryption doesn't work.. :P Am I going about this all wrong or does anybody know an easier way (besides getting an open source algo class such as Crypto++) I'm super new to fooling with the bits/encryption for(;num of rounds;) { char ^ Key; Round bit shift; } Jul 19 '05 #4

 P: n/a Hi Richard, "Richard" schrieb im Newsbeitrag news:3b**************************@posting.google.c om... I'm looking to do my own basic encryption. I've been tyring to do a concept such as: Am I going about this all wrong or does anybody know an easier way I've written numerous quite safe encryption (scrambling) algorithms. Don't use something too simple if you want to be safe. To test your encryption you could write a program that prints or displays image data. Then, encrypt an image and see what it displays then. If the original image is "shining thru" the algorithm is bad. I've had much success by using random numbers and loops that depend on previous data. You need at least two or more variables that are combined with the source data. You could do something like this: void simple_encrypt( int* dest, int* src, int count, int& v3, int& v4 ) { int v1 = 0XFC03AB9D; int v2 = 0X4903CB0A; v3 = rand(); v4 = rand(); for ( int i=0; i

 P: n/a BTW, for random number generation, you could (if you're programming for the IA-32 architecture, like Pentium 1-4), use the processor's uptime counter in the seed value: __int64 GetProcessorClock( void ) { _asm rdtsc; } void SetRandomSeed( void ) { srand( (unsigned)( time(0) ^ GetProcessorClock() ) ); } The value from RDTSC is unsuitable for using in loops, because it increments with each processor cycle. If your routine uses a fixed amount of cycles, the results might be predictable. But you can use it in an initial value. ;-) Jul 19 '05 #6

 P: n/a "Ekkehard Morgenstern" wrote in message news:bp**********@online.de... | I've written numerous quite safe encryption (scrambling) algorithms. Don't | use something too simple if you want to be safe. To test your encryption you | could write a program that prints or displays image data. Then, encrypt an | image and see what it displays then. If the original image is "shining thru" | the algorithm is bad. | | I've had much success by using random numbers and loops that depend on | previous data. You need at least two or more variables that are combined | with the source data. The "Secure Programming Cookbook" of John Viega & Matt Messier has a free chapter about random numbers available online: http://www.oreilly.com/catalog/secureprgckbk/ (book page) http://www.oreilly.com/catalog/secur...apter/ch11.pdf I also vaguely remember, from reading TAoCP, Knuth stating something like "Don't use a random approach to generate random numbers". For both encryption and random number generation, which are closely related, I would rather rely on published and well-studied algorithms. I'm not a cryptanalyst, and I am confident that an expert can do much better than me. Too many commercial (and free) applications/OSes suffered security loopholes because of weak random number generation. I don't trust myself to invent something better... This said: the OP was asking for 'basic encryption' -- and your post and suggestions are very helpful and fully relevant in this context :) Kind regards, Ivan -- http://ivan.vecerina.com/code/coopfish/ Jul 19 '05 #7

### This discussion thread is closed

Replies have been disabled for this discussion.