473,698 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12988
"Richard" <sh*****@hotmai l.com> wrote in message
news:3b******** *************** ***@posting.goo gle.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;
| }

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.go ogle.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
indistinguishab le 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.go ogle.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*****@hotmai l.com> schrieb im Newsbeitrag
news:3b******** *************** ***@posting.goo gle.com...
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 GetProcessorClo ck( void ) { _asm rdtsc; }
void SetRandomSeed( void ) { srand( (unsigned)( time(0) ^
GetProcessorClo ck() ) ); }

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************ ******@onlineho me.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
9285
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. # No warranty express or implied for the accuracy, fitness to purpose
2
1483
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 data encription at the client side to students my idea is to build a simple <FORM> on the webpage with 2 text fields and a submit button. The student fills in the text field on top and click Submit. At this moment, onsubmit() sends the text field...
2
1311
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? Or, am I forgetting some step(s)? If I can ask, what exactly does ENCRYPTing do to an unencrypted MDB file?
12
1447
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
2557
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 using User 2's Public Key. User 2 Decrypts the transmission using his Private Key to get the orignal message. Is the above correct?
28
2451
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 I should perhaps learn a more powerful language to program my own apps. I got a "Beginning C" book, but the C programs won't compile in the free compilers I have downloaded. The syntax is different. I guess I have to buy a programming package,...
2
2508
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
1710
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: System::String^ s = gcnew System::String(basic_s.c_str()); //here basic_s is a basic string in c++ But I found s contains less charactors than the original basic string, some charactors are missing.
7
4082
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. Please let me know if it is really simple to crack. Regards j1mb0jay
0
8680
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8899
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.