Skip to main content
GameDev.net gamedev.net
🔒 Locked

"Bah Wtf" Encryption

Started by Afr0m@n Sep 1, 2006 at 2:38 PM 24 replies 3.4k views
Original Post
Afr0m@n
Afr0m@n
Is it hypothetically possible to represent any string of any length that is ASCII encoded by using the string "Bah Wtf" as an encryption? Here's the status so far; To encrypt, you'd simply do this: - Read string from file into memory. - Copy the data into another string (so the original data is retained). - For each letter in the new string, replace with the string "Bah wtf". - If you end up with too many "Bah wtf"s, simply delete the ones that are in excess. Now, obviously, I'm trying to figure out how to convert the string back again, should that be neccessary. Does anyone have any suggestions? Here's my current, very theoretical approach; - Make each letter represent a different number based on the way it's being read (from left to right or right to left etc.), and then store a certain amount of bytes in the encrypted file telling the decryption file which way to read the string and which numbers the letters should represent based on what way the string is read. As far as I can see, the only way to make this work would be to store some extra data, but ideally I'd like to achieve an encryption and decryption of ANY string of ANY length without any extra data storage. Is this even possible?
_______________________Afr0Games
Alpha_ProgDes
Alpha_ProgDes
Quote:
Original post by Afr0m@n
Is it hypothetically possible to represent any string of any length that is ASCII encoded by using the string "Bah Wtf" as an encryption?

Here's the status so far;

To encrypt, you'd simply do this:

- Read string from file into memory.
- Copy the data into another string (so the original data is retained).
- For each letter in the new string, replace with the string "Bah wtf".

Now I'm no expert, but wouldn't this make the file 6x bigger?
Quote:
- If you end up with too many "Bah wtf"s, simply delete the ones that are in excess.

If you delete the "bah wtf"s, then you delete the letters, do you not?

Beginner in Game Development?  Read here. And read here.  
Afr0m@n
Afr0m@n
Quote:
Original post by Alpha_ProgDes

If you delete the "bah wtf"s, then you delete the letters, do you not?


Yes, which is why the original data should be retained in the program's memory so that I'll have a chance to figure out what to do to decrypt the encrypted string.

_______________________Afr0Games
Evil Steve
Evil Steve
Quote:
Original post by Afr0m@n
Quote:
Original post by Alpha_ProgDes

If you delete the "bah wtf"s, then you delete the letters, do you not?


Yes, which is why the original data should be retained in the program's memory so that I'll have a chance to figure out what to do to decrypt the encrypted string.
If you already have the un-encrypted data, what's the point in encrypting it in the first place? You can't save the encrypted data, since all you'll get is a file full of "Bah WtfBah WtfBah WtfBah Wtf" with no way to relate it to the original data.
Joakim_ar
Joakim_ar
No. What you're trying to do is not just encryption, but compression. Ie. you want strings longer than "bah wtf" to be compresed into that string. It is impossible to make a compression algorithm that can reduce the size of any input, which implies that your encryption is not possible.

If all the strings are 'encrypted' to "bah wtf", then "bah wtf" does not contain any information at all. Hence you need to store the entire string (be it encrypted or compressed with another algorithm) besides it in the file.
Conner McCloud
Conner McCloud
The solution is obviously bitfields. "Bah" represents a one, and "WTF" represents a zero. Its pretty weak, though...to make it stronger, just add some random "LOL" s in to throw off the reader. That should stump even the smartest of codebreakers, who would likely take one look at the file and then their heads would explode.

CM
Conner McCloud
Conner McCloud
Quote:
Original post by Emmanuel Deloget
1 bit => 4 bytes ?

Might need compression. Something that could turn "bah " to 0 and "WTF " to 1. Er... no...

You might be onto something there. Encrypt it using WTFLOLEncrypt, then compress it using your simple mapping. You'll get the original message back, but those evil hackers will assume you've hidden something inside the plaintext. Suckers.

CM
Emmanuel Deloget
Emmanuel Deloget
template <typename T> struct wtf_char{  typedef T value_type;  std::string& output;  wtf_char(std::string& out) : output(out) { }  void operator()(const value_type& v)  {    if (sizeof(value_type) == 1)    {      encrypt_char((char)v);    }    else    {      std::vector<char> char_mapping(sizeof(value_type));      std::copy((char*)&v, ((char*)(&v)) + sizeof(value_type), char_mapping.begin());      for (size_t i=0; i<char_mapping.size(); ++i)      {        encrypt_char(char_mapping);      }    }  }private:  void encryt_char(char c)  {    for (i=0; i<8; i++)    {      output += ((c >> (7-i)) && 1) ? "Bah" : "WTF";    }  }};void enwtfing(const std::string& input, std::string& out){  std::for_each(input.begin(), input.end(), wtf_char<std::string::value_type>(out));}


Should not work too bad, if there is no compilation error :)
Sc4Freak
Sc4Freak
Afr0m@n:

If you replace every letter with "Bah WTF" then you've basically reduced your string to rubbish. You have no way to relate the encrypted string with the original. What's worse, you're truncating it so that you've basically removed information.

Compression of the encrypted string is needless because the encryption makes no sense. You may as well throw out your data. Because what you're trying to do is analogous to writing a block of memory to 0's and then trying to determine what used to exist there based on a big bunch of 0's.
Zahlman
Zahlman
Please don't stumble around in the dark trying to guess at how encryption works. Too many people do this and come up with absolute nonsense. Go [google] yourself up some tutorials instead. This is not in any way shape or form trivial stuff: while it's easy to implement most encryption algorithms given the description (yay, pseudocode->real code - big whoop), there are very, very few people *on the planet* who could come up with a *new, meaningful* encryption algorithm from scratch.

Keep in mind that "omg, I didn't tell them how teh algorithm works!!!11" is a poor standard for encryption strength. Data analysis techniques exist for figuring out all kinds of things along these lines. The *good* algorithms are the ones where the author can tell everyone *exactly* how to write code to break the encryption, but it's *still* effectively impossible for the program to actually *do so* (typically, because step one of the process is "here's an ungodly h00g number that is the product of two primes; you need to factor it before you can get any further. Oh, and here's mathematical proof that there's no way around that.")
Will F
Will F
Quote:
Original post by Anonymous Poster
Quote:
Original post by Zahlman
...typically, because step one of the process is "here's an ungodly h00g number that is the product of two primes; you need to factor it before you can get any further...


So if a group creates a massively large distributed application, multiplying every known prime number by every other prime number, and those we continue to find, and then databases those pair->result solutions, and then makes public domain queries of the results possible, a lot of the workings of the net just got broken?

Suppose that SETI is really doing the first part of this?


I wouldn't be too worried about it, here's some interesting reading: Brute Force Key Attacks Are for Dummies. Here's a quote from Jon Callas, CTO of PGP corporation (which means he knows what he's talking about).

Quote:
Modern cryptographic systems are essentially unbreakable, particularly if an adversary is restricted to intercepts. We have argued for, designed, and built systems with 128 bits of security precisely because they are essentially unbreakable. It is very easy to underestimate the power of exponentials. 2^128 is a very big number. Burt Kaliski first came up with this characterization, and if he had a nickel for every time I tell it, he could buy a latte or three.

Imagine a computer that is the size of a grain of sand that can test keys against some encrypted data. Also imagine that it can test a key in the amount of time it takes light to cross it. Then consider a cluster of these computers, so many that if you covered the earth with them, they would cover the whole planet to the height of 1 meter. The cluster of computers would crack a 128-bit key on average in 1,000 years.

If you want to brute-force a key, it literally takes a planet-ful of computers. And of course, there are always 256-bit keys, if you worry about the possibility that government has a spare planet that they want to devote to key-cracking.
Winterhell
Winterhell
why dont you just replace the whole string with one "bah wtf" and then you'll save more space,to decrypt the string you'll need to make a lottery function that generates rand number of random symbols.If you have strong enough luck,your problem is resolved
Will F
Will F
Quote:
Original post by Anonymous Poster
He knows what he's talking about, but what he's talking about isn't public key RSA (the topic of the posts you quoted) but a regular symmetric crypto such as AES.


The point was that it's easy to underestimate the power of exponentials, they can be some rather large numbers. Regardless, I'm going to bow out of this discussion as encryption isn't an area i'm particularly knowledgeable about.
Sirisian
Sirisian
whatever happened to XOR encryption? :/ Most people have problems decrypting that as is, or just swap every other letter? People have to be dedicated to crack something. There is a very blurry line between obfuscating things and encrypting them. Best way I know of to encrypt is to rearrange bits using a fast algorithm.
keen
keen
I dont think RSA encryption will be able to help him out with encrypting&decrypting something to "bah wtf".
Clearly a custom made algorithm has to be made here.
JohnBolton
JohnBolton
Quote:
Original post by Afr0m@n
Is it hypothetically possible to represent any string of any length that is ASCII encoded by using the string "Bah Wtf" as an encryption?


Yes. Treat the input string as a base-128 number. Then the output is simply that number of repetitions of "Bah Wtf". Not very practical, though.

Correction: You have to also add 1 to the number, so that an empty string would output 1 occurence of "Bah Wtf" (instead of 0).
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
AntonyCoder
AntonyCoder
Hmm. Dosen't quite work does it? Shame. Cos it sounded great on paper.

Xai
Xai
No public private key system is actually safe AT ALL, if there is a large enough database of key pairs to keep them cached. As a matter of fact this is the whole premise of the exportable encryption rules, all of the common exportable encryptions do not take any significant time for a Department of Defense team to crack, because they had the multi-terrabyte key pairs pre-generated in a database. So it is back to the obscurity security system again - as in, you hope they don't bother looking up your particular encypted packets ... now the arbitrary limits on key length are not because teh government can't / hasn't / or won't keep a database of the larger systems, someday. It just was not considered feasable / economical at the time the rules we're created. If you notice how much a room of clustered databases can store these days, you'll realize that it is thousands of times larger than what could be stored in such a volume / power draw just a decade ago. Of course this doesn't keep pace with exponential functions, so upping to 128, 160, 192, 256 bit etc will keep ahead of the curve - but 80-bit is already fairly trivial today, and 128 bit is probably within reach of a truely dedicated corperate or government entity.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.