What are use cases to use `SecureRandom.base64` over `SecureRandom.hex`? [closed] - ruby

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
Objective is to create a random encoded string. But I'm not a computer science major, any explanation in layman terms would be much appreciated.
irb(main):002:0> SecureRandom.base64
=> "9VpzpvCR4ww/ZQc9lN148A=="
irb(main):003:0> SecureRandom.hex
=> "29b6cd61ec3e58959b006b6d98550b97"

The difference between Base64 and hex is really just how bytes are represented. Hex is another way of saying "Base16". Hex will take two characters for each byte - Base64 takes 4 characters for every 3 bytes, so it's more efficient than hex. ... If it does matter, then clearly Base64 is better on that front.

Related

Ruby - Convert Integer to ASCII value [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 2 years ago.
Improve this question
I have been looking around the internet, but have not found a way to convert a integer into a ascii value in Ruby.
Anyone have any idea how?
Try
your_number.chr
here's the doc
In your case, you can use chr to convert integer to ascii.
>> 65.chr
A

How to store a secret word? [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 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.

Sorted values not correctly sorted [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 am stumped by the sorting algorithm that is employed by the sorting method for a hash object. I have an hash with the following key values which are all floats.
0
0.0113867473179591
103.77896959717717
2.039453159239391
99.99575298164214
These are the values I got when I use map_values.values.sort(). I don't understand why 103.778.... comes before 2.0394...
Are your values strings? This kind of sorting makes sense when dealing with strings. If you want to sort by the float values you should convert the strings to floats.
map_values.values.map(&:to_f).sort

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.

Determine that the languages accepted by two NFA's are same or not [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 two NFA's.
I need to determine whether both recognize the same language
I would be much obliged if anyone could be so kind enough to explain how to do this.
You can get a canonical representation of an NFA by computing its equivalent minimal DFA.
If two NFA's have the same canonical representation, they accept the same language.

Resources