How to store a secret word? [closed] - algorithm

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 7 years ago.
Improve this question
Is there an algorithm for handling secret words without storing them in clear text or using a reversible encryption?
Necessary operations include
getting the length of it, so that we can generate indexes
testing whether the n-th character matches a specific character

If you want to match the n-th character with another character, the encryption becomes easily reversible. An adversary just has to test all characters with all possible values. So in ASCII that will be 256*8=2048 for an 8 character password.
You should normally store a SHA-256 or SHA-512 of the password (possibly prefixed with a random salt) and compare this value against the user inputed value SHA-256/512ed.
You can also repeat the SHA-256/512 operations several thousand times to make attacks more difficult.

Related

Combine sequence of positive integers into one unique integer [closed]

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 months ago.
Improve this question
So I've got a list of positive integers and I want to combine all elements into one unique integer. But I am only able to use basic arithmetic (+, -, *, /).
The result should have the semantics of a hash for the input sequence. So no other sequence should be able to produce it.
Any suggestions how I could tackle this problem?
Interpreting "hash" to mean that the output domain is bounded, it's not possible to "hash" an unbounded input sequence to a unique output. Those numbers can only be compressed so much without losing information.
If this were possible, compression ratios for any digital information could approach infinity.

How to design an algorithm to determine how many numbers are in a string? [closed]

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 2 years ago.
Improve this question
Design an algorithm to determine how many numbers are in a string. Example, given the string "Hello people from the 4 worlds, this is my only 1 program", the output must be 2.
Basically you need to write a simple parser to parse out the numbers in your string. To do that you need to be able to recognise a number correctly, which is a little more complicated than just recognising digits. Something like "-12,348.971" is a number, but contains the characters -,. which are not digits. However, the string "-,." is not itself a number.
Read through the string, character by character. When the parser finds the start of a number, count one more number found, and read through all the characters that form that number. Read '123' as a single number, not three numbers. When you reach the end of the number skip over non-number characters until either you find the next number or you reach the end of the file.
You might want to read up on writing a simple parser in the language of your choice.

How to find the minimal number of bits to encode a set of known strings? [closed]

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 5 years ago.
Improve this question
How to find the minimal number of bits to encode a set of known strings?
If the set of strings is known to both sender and receiver, then you need zero bits to transmit it. (In effect, the message is "Use the known set." I know that sounds silly, but it is often part of a comms protocol.)
If you need to send a single string from the set, you can send its ordinal index, using log2 N bits, where N is the size of the set.
if you are repeatedly sending messages containing a single string from the set but the frequency distribution of the messages is non-uniform, you can Hoffman-code the ordinal. That will optimize the total size of all messages over time.
I don't know exactly if you require this one but still have a look at it , it might help you . Let me know if it does:
Compression algorithm

How to built algorithm that can generate random set of digits and letters [closed]

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 6 years ago.
Improve this question
On what language is more easy to code that kind of algorithm and make it more flexible to changes.
It's pretty easy to do, at least in widely used programming languages that I'm aware of (e.g. C++, Java, etc).
Store all possible characters in an ordered collection like array or a string. For example, you can make a string that contains all letters and digits like so:
// Exact syntax depends on your programming language.
//
// I used a string for simplicity here but some languages don't allow
// you to access individual string characters so you'll need an array.
//
string a = "abcdefghijklmnopqrstuvwxyz0123456789";
Generate a random number between 0 and length(a) - 1 (size of your character set array minus one).
Use the number you generated as an index and extract the character from the array at that index.
Congratulations! You've just generated one random character from your character set. Go back to step #2 and repeat N - 1 times (N is here the total number of characters you want to generate).

String manipulation using MD5 in rails 3 [closed]

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 8 years ago.
Improve this question
I have a big string
approx 4000 characters
i want encrypt and decypt it using MD5 because of i want to do convert in a small string please help me a lot of finding i found Base64 but it is not our solution please any one help me
my_string="abcdefghhhhhhhhhhhhhhhhhhhhhh"
Base64.encode64(my_string)
it gives us very lengthy string.
Encrypting a string will not make it smaller, it will at best be the same length. I think what you are looking for is a way to compress your string. That aside, MD5 is a one-way hashing algorithm, that means that it is designed, so there is now way of recovering the source string (it turns out that it was designed rather poorly).
MD5 is a one-way hash, you can't decrypt it.
To encode a string use Digest::MD5.hexdigest('foobar') but for most purposes I'd say use a better hashing algorithm; MD5 has been broken for a long time.

Resources