Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
What would be the most space efficient way to encrypt some data such that the encrypted data satisfies any one of the following constraints:
1) Fits in 32 bytes or less of hexidecimal (64 characters)
2) Fits in 28 bytes or less utf-8 characters (28 characters)
3) Fits in a 64 bit unsigned integer
The goal is to encrypt some data (like user id + nonce) and store it publicly on a blockchain and then decrypt it later on a server. The storage requirements of the blockchain I'm using (Stellar memos -- https://www.stellar.org/developers/guides/concepts/transactions.html#memo).
I'm looking for space-efficient encryption algorithms, or some combination of encryption + lossless compression that could make it fit.
There will be two inputs to encrypt: a user id and a nonce -- let's just assume we can fit both inside of 25 characters.
Example:
encrypt("7863439|12343567") -> "385acd1ca0ab619b9f832025fa358b69"
decrypt("385acd1ca0ab619b9f832025fa358b69") -> "7863439|12343567"
Use AES-256 or Twofish-256 You will have 256 bit = 32 bytes. This fits your 1st requirement. Both are space efficient. Well it depends of course how you define "efficient".
Maybe you could use hashing instead of encryption. Hash your data and store it on a server. Finding input data that will collide with your stored hash is designed to be difficult. Use a strong hashing algorithm that outputs 32 bytes of data, and you're done.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I would love to make my own data encryption method like Base64 and such. (preferably in Python.)
Would it be secure if I assigned "a" to for say a random number between 1-100 and a random letter or such. (for example 53f) and other letters are combinations and its random. But then how would I make a decoder, sorry for the long question haha. Thanks!
Do not start by making your own encryption method. Start by reading Bruce Schneier's Memo to the Amateur Cipher Designer.
Then write your own versions of the simpler existing ciphers: Caesar, Vigenere, (both of historical interest) RC4, Feistel. That will help you with the structure of ciphers, particularly RC4 -- a stream cipher and Feistel -- a block cipher framework.
Base64 is not a cipher, as has been pointed out. It is a useful exercise to write your own Base64 encoder/decoder, though most modern languages include one in their library anyway. That exercise helps you practice bit manipulations.
When you have done all that, find an implementation of AES that you are happy using. Any cipher you devise will not be as secure as AES.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Suppose I have 8 bits. Then total possible combinations would be 2^8 . Is there some encryption technique I could use so that I can identify all those 256 numbers with less bits ( say 5 or 6 bits). I know this is kind of hard ( and impossible ) . But if someone could help.
No, this is not possible.
At least 2 of the original 256 states would be mapped to the same encoded state. Therefore you cannot reconstruct the original stated from the encoded state.
see Pigeonhole principle
According to the pigeonhole principle there's no there's no way to stuff 8 bits of information in 5 or 6 without loss of data.
With larger sets of data you can use lossless compression techniques to reduce the amount of data needed, but those techniques have overhead that would take more information than could be saved from just 8 bits.
The only way you can compress 8 bits is to restrict the data set so that patterns can be encoded. e.g. if exactly one of the first two bits can be 1 then you can "encode" that to save one bit, but that limits the number possible values to
2^7.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have a login and password that I need to store in my database. What is a safer way to encode them (I use AES algorithm): as one string with separator between login/pass, or as a two separate strings?
Encoding has to be reversable, so please don't mention hash.
Safety has not much to do with your choice. If you use AES with mode different than ECB and PKCS7/PKCS5 Padding you can either encrypt logins and passwords alone or logins and passwords seperately. It depends on wheather you will need a login without a password in your implementation. You will probably use the same key to encrypt both login and password. So splitting is by no means an additional security measure. If you woudl use some salted PKDF keys can be different for each record, but attacker still needs only to get the master password and a salt.
That's no any additional security in encrypting them together or separately.
However, you should also choose wisely cipher mode/initial vector - for CBC and CTR (and CFB?) input to encryption is xored with encrypted Initial Vector, so having the same vector for two encrypted passwords, xoring them would allow to get xor of original passwords, which can leak information.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I'm a total beginner to encryption and I don't really understand anything about it.
Let's say I had a file TOPSECRET.BIN. What if I just:
read file byte by byte
XOR each byte by 69
write "encrypted" data back into file
Sure it's simple, but how is anyone ever going to know how to decrypt that?
The main problem is that your ciphered text will still exhibit the hierarchical structure of the cleartext. So if the cleartext was english text, the same hierarchical structure you see in the english phrases will be in the ciphered message.
If you XOR each byte with 69, figuring it out will be as simple as just trying 256 bytes to XOR. Plus language structure can be used for cryptanalysis.
You can use XOR for perfect encryption, though. Just choose a random sequence of bytes with length equal to your text and XOR it byte by byte. The random bytes will be your key. However, it will be as hard to communicate this key securely as it would be the message itself. And if you reuse this key, it would be easy enough to analyze multiple encrypted messages to figure it out.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
ctr mode makes it possible to use a block cipher as a stream cipher but how strong will be the encryption in this mode ?
Ultimately it depends what you mean by strong. For example from an encryption point of view, i.e. taking the ability of an attacker to decrypt your ciphertext without access to the key, it should be as strong as any other use of AES256 (there is some dicussion on differential analysis between individual cipher blocks with a known plain text but that would be a weakness of the encryption algorithm not of the CTR mode itself).
In the end whether CTR mode is appropriate will depends what you want to apply it to and how you implement it. A couple of things to bear in mind when using this mode would be:
The same nonce/counter sequence will create the same cipher stream therefore you must ensure you do not ever use the same values for a given key. Otherwise it might be possible for an attacker given a message with a known plain text to reuse the cipher stream to decrypt your current message).
As the stream cipher is XORed with the plain text it means that a 1 bit change in the ciphertext directly results in that bit changing in the decrypted data, therefore some sort of message integrity is paramount, most likely a HMAC so that an attacker cannot realistically generate the hash and correct that as well.