tags:

views:

78

answers:

3

what sha1() will do to russian or any other non english letters? Will sha1() always return english letters?

+1  A: 

sha1() has nothing to do with russian or any other non english letters (or any other letters - thanks to enlightening comment from Greg Hewgill)
this PHP function returns returns a string, consists of only digits and latin letters, only first 5 of them

Col. Shrapnel
It doesn't have anything to do with *english* letters, either. It sounds like you're thinking of the hexadecimal representation of the 160-bit result.
Greg Hewgill
OMG thinking? what is it?
Col. Shrapnel
The output of the SHA-1 algorithm is a 160 bit number. Normally, this is converted to a hexadecimal representation for easier reading, such as `7a788f56fa49ae0ba5ebde780efe4d6a89b5db47`.
Greg Hewgill
sha1() is looks like function name, not algorithm,
Col. Shrapnel
Right, I see the documentation for the PHP function [`sha1()`](http://php.net/sha1) has a *raw_output* parameter that lets you choose whether you want the hexadecimal representation or not.
Greg Hewgill
+9  A: 

SHA-1 doesn't care about character encoding. It only considers a stream of bytes. The output will always be a 160 bit number.

Anonymouse
What's worth adding is that usually you convert somehow the input string (characters) to stream of bytes and then apply the SHA-1 algorithm. Depending on the encoding used in the first step, the overall result might be (and practically will be) different.
Grzegorz Oledzki
+4  A: 

sha1 works on bytes, not letters, and it produces a 160-bit binary number. That number is usually represented in hexadecimal notation, so, yes, it will always return english letters ("a" to "f", to be precise).

Marcelo Cantos