473,835 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Encryption

I've been trying to write a basic encryption algorithm, not really
intended for use as a secure means of protecting data, but to help me
learn things like bitwise operations.

Just wondering, how easy would it be to crack what I've come up with:

FILE * inFile;
FILE * outFile;
this->inputfile = infn;
int k = 0;
char pc = 211;
char ppc = 47;
int count = 17;
int klen = this->key.length() ;
string key = this->key;
char nc;
char encChar;
int counter = 347;
int offset;
string out;
inFile= fopen(infn.c_st r(),"rb");
outFile= fopen(outfn.c_s tr(),"wb");
char khash1 = key[0];
char khash2 = key[0];
char khash3 = key[0];
for(int kle=0;kle<key.l ength();kle++){
khash1 &= key[kle];
khash2 |= key[kle];
khash3 ^= key[kle];
}
nc = fgetc(inFile);
int forloops;
GetFileSize(&fo rloops);
int fl = 0;
for (fl;fl<forloops ;fl++){
counter++;
encChar = (key[k]^nc);
encChar = encChar^(pc^ppc );
ppc = (pc+((key.lengt h()*(key[k]+4))*(count++/23)));
pc = encChar;
offset = ((counter++)%(k ey[k]));
encChar += offset;
encChar ^= khash3;
encChar ^= khash2;
encChar ^= khash1;
fputc ( encChar, outFile );
k=(++k<klen?k:0 );
nc = fgetc(inFile);
}
fclose (inFile);
fclose (outFile);

Thanks,

Harry

Jul 20 '06 #1
2 1425
haz...@gmail.co m wrote:
I've been trying to write a basic encryption algorithm, not really
intended for use as a secure means of protecting data, but to help me
learn things like bitwise operations.

Just wondering, how easy would it be to crack what I've come up with:
[snip]

You're in the wrong newsgroup. Here, we discuss the C++ *language*, not
arbitrary algorithms and applications. See this FAQ for what is
on-topic here:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

Cheers! --M

Jul 20 '06 #2
In article <11************ **********@75g2 000cwc.googlegr oups.com>,
ha****@gmail.co m says...

[ Warning: this post is long and only marginally topical at best... ]
Just wondering, how easy would it be to crack what I've come up with:
[ ... ]
counter++;
encChar = (key[k]^nc);
encChar = encChar^(pc^ppc );
ppc = (pc+((key.lengt h()*(key[k]+4))*(count++/23)));
pc = encChar;
offset = ((counter++)%(k ey[k]));
encChar += offset;
encChar ^= khash3;
encChar ^= khash2;
encChar ^= khash1;
The first thing you should realize is that exclusive-or is
commutative, so ((a xor b) xor c) is equivalent to (a xor (b xor c))
(and likewise if you add a 'd'). So, your first step in figuring out
what this really does is to take that into account. For example, the
last three lines in the loop are equivalent to:

// this outside the loop:
khash = khash1 ^ khash2 ^ khash3;

// and then this in the loop:
encChar ^= khash;

Ultimately, what you have seems to reduce to:

ch ^= X;
ch += Y;
ch ^= Z;

For appropriate definitions of X, Y and Z.

Since Z remains constant throughout, it has no real effect on the
relative frequencies of characters, so for most practical purposes
it's a NOP. The way you've defined Y is almost more troublesome -- I
suspect in effect, it ends up giving the attacker more information
than he'd have without it. Consider what happens if you encrypt a
message that starts out as all zeros. For each character, Y starts at
0, increases to key[n], and the cycles back to 0 again. As such, here
you almost have things working in reverse: the main thing that's
keeping your key secret is the fact that it's being "encrypted" using
the original text as the encryption key. If that wasn't happening,
you'd be sending the key, ready for the attacker to use it.

In particular, if I take two messages that were encrypted with the
same key, I can xor them together, and everywhere the letters in the
original messages were the same, what I have left is your 'counter++
% key[k]'. Given the redundancy of normal text, that's going to
happen quite a lot. It won't take a whole lot of analysis of the
result to find your entire key.

Your definition of X is almost certainly the most useful. In
particular, it's the only one that forms any chaining effect --
making the value of one output character depend not only on input[n]
and key[n], but also on input[n-1] and key[n-1]. Unfortunately, I'm a
bit uncertain about some of it -- in particular:

ppc = (pc+((key.lengt h()*(key[k]+4))*(count++/23)));

looks more or less like you picked it almost randomly -- it looks as
if 23 (for one example) was pretty much just an arbitrary number.
Ultimately, I'm not sure how much all this machination really
accomplishes (if anything at all).

While I haven't attempted a serious attack on this, my immediate
reaction isn't particularly positive. I'm fairly certain anybody who
bothers to work through this:

http://www.schneier.com/paper-self-study.html

(for only one obvious example) can break your cipher fairly easily.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7153
by: Cliff | last post by:
We are trying to connect to 3 different Oracle databases using MS Access as the front-end and ODBC as the connection. The problem that we are having is that 1 of the databases requires a CRYPTO_SEED. With the sqlnet.ora file configured for the encryption, the other 2 databases won't connect and vise versa. Is there a way to make the connections use encryption when required and not use it when not required. We are using 9i client...
113
12363
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same algorithm work with strings that may or may not be unicode 3) Number of bytes back must either be <= number of _TCHARs in * sizeof(_TCHAR), or the relation between output size and input size can be calculated simply. Has to take into account the...
7
2248
by: Alan Silver | last post by:
Hello, I am writing a page where sensitive data is collected (over SSL) and stored in a database. I have been looking at the .NET encryption classes, but am a bit confused as to which is best for my purposes. There seem to be quite a few different ways of doing it, and I'm not sure what's most suitable for me. Anyone any suggestions? I only need to be able to store the data in such a way that someone without access to my (to see how...
2
1538
by: Sumit Gupta | last post by:
Can anyone please tell me how to encrpt string or any kind of Data. Also the Algorithm of Compression. Any Link tutorial etc. Like : Zip or RAR Formats etc.
9
5168
by: sweety | last post by:
Dear All, How to encrypt a C data file and make binary file and then have to read a bin file at run time and decrypt the file and have to read the data. Any help to achive this pls. Would be great if any sample source code provided. Thanks, Sweety
4
4149
by: pintu | last post by:
Hello everybody.. I hav some confusion regarding asymmetric encryption.As asymmetric encryption it there is one private key and one public key.So any data is encrypted using private key and the same is decrypted at client side using public key and vice-versa..Now i hav confusion like i.e. * Are both the keys available to both sender and receiver.? * When data is encrypted using public key ,Is the same data decrypted using private key(...
1
3086
by: =?Utf-8?B?bWljcm9ob2Y=?= | last post by:
Short version: Is there a way to configure (preferably programmatically) the max encryption strength that will be used by the framework when connecting to a particular SSL-protected web service? Long version: Historically, browsers could only be exported to certain countries if they supported only 40 and 56 bit encryption; 128 bit was restricted. I believe, based on my readings thus far, that this refers to the strength of the...
11
5056
by: John Williams | last post by:
I've written a simple program to do XOR encryption as my first foray into understanding how encryption works. The code compiles fine, however it segmentation faults on every run. using gdb to debug it let me narrow the problem down to the Cipher function I think it faults at line 84 or 85. The program makes it's first read/cipher/write pass without issue but the second pass kills it. Using gdb to print the variables left showed me the...
22
7703
by: j1mb0jay | last post by:
I have had to create a simple string encryption program for coursework, I have completed the task and now have to do a write up on how it could be improved at a later date. If you could look through the code and point me in the correct direction one would be very grateful. Example Input : j1mb0jay Example Output 1 : rZHKZbYZWn/4UgL9mAjN2DUz7X/UpcpRxXM9SO1QkvkOe5nOPEKnZldpsB7uHUNZ Example Output 2 :...
19
3310
by: klenwell | last post by:
Another request for comments here. I'd like to accomplish something like the scheme outlined at this page here: http://tinyurl.com/3dtcdr In a nutshell, the form uses javascript to hash (md5) the password field using a random one-time salt (nonce) -- generated by php and pasted in the form -- that is then posted with the hashed password
0
9810
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
10815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10562
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
9348
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7768
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6968
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
5805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4434
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3092
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.