473,405 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Basic encryption

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 12973
"Richard" <sh*****@hotmail.com> 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
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
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

Hi Richard,

"Richard" <sh*****@hotmail.com> 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<count; ++i ) {
int v = *src++;
v = ( ( v1 ^ v ) - ( v2 ^ v ) + ( v3 - v1 ) - ( v1 + v4 ) );
v1 ^= v2 + v3;
v2 ^= v1 - v4;
v3 -= v1 + v2;
v4 += v2 - v1;
*dest++ = v;
}
}

You would have to keep the values of v3 and v4 elsewhere to be able to
decode the data later on. The encoding should be designed such of course
that you can reverse all operations.

The code I gave is just an example how you could do it, just play around
with various combinations of +, - and XOR (^). Those are easier to do in
reverse than other operations.

Have fun! :)
I hope this helped! :)

Regards,
Ekkehard Morgenstern.
Jul 19 '05 #5
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
"Ekkehard Morgenstern" <ek******************@onlinehome.de> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
2
by: Eli | last post by:
Hi gurus, My question is about exchanging data on a basic HTML page between a JavaScript piece of code and a Java client-side <APPLET> residing on the same webpage. To demonstrate the idea of...
2
by: MLH | last post by:
1) Create secure workgroup system database, remove user ADMIN from the ADMINs group 2) Encrypt the source MDB front end database 3) Create 'n distribute MDE from the encrypted MDB Is that all?...
12
by: Ralf Dieholt | last post by:
I still don´t get it - what is the advantage of C ? I can program anything in BASIC V2 on a C64, does C have any advantages over BASIC V2 ? Seems to be more cryptic than BASIC to me.
6
by: Sahil Malik [MVP] | last post by:
Public Private Key Pairs - How do they work? ----------------------------------------------- I was looking at a presentation recently in which it was suggested that - User 1 Encrypts a message...
28
by: grappletech | last post by:
I took Pascal and BASIC in a couple of beginner programming courses about a decade ago and did well with them. I am good with pseudocode, algorithms, and the mathematics of programming. I decided...
2
by: damod.php | last post by:
what's the Basic Encryption method used in mysql, whats iner join whats outer join ,diff b/w.what are the encryption methods used to encrypt the user name and password.in php/mysql
1
by: Vivienne | last post by:
Hi, I am using a c# library in my c++ project. so I have to convert a basic string to System::string to make use of a function that takes System::String as argument. I did it like this: ...
7
by: j1mb0jay | last post by:
I have created some simple string encryption in C# to be able to store passwords in a database without them being stored in plain text. I have attached a encrypted passage from a book I like....
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.