2
$\begingroup$

Textbooks most of the time assume that a message, say "secret", is already represented in number format, say "8614" (just as an example!). But how exactly is this conversion achieved?

I imagine it to happen something like that:

  1. "secret" is converted into the binary format, say "1001001" (names like ASCII or UTF-8 come to my mind, though I am not sure)
  2. 1001001 is somehow converted into a number, in above example "8614"

Could you please give me more details or some references so I can look it up?

$\endgroup$
  • 1
    $\begingroup$ This is not really related to crypto as such, much less encryption specifically; all computer processing of characters or text is based on character encodings. Over the past 60+ years dozens of major schemes with at least thousands of variants have been used, although for the past 30 years a concerted effort has produced substantial convergence on Unicode (or substantially equivalent, ISO/IEC 10646) (often but not always encoded as UTF-8) and ASCII which is a subset of both Unicode (via 8859-1) as a charset and UTF-8 as an encoding. $\endgroup$ – dave_thompson_085 Jun 8 '19 at 1:10
4
$\begingroup$

Cryptographic schemes handle byte strings. To convert a string to a byte string, you need some encoding like ASCII (which can't handle every character) or UTF-8 (which can handle the entire Unicode).

Some specific schemes, like RSA, do need to interpret the byte string as a number. This process is defined in the scheme specification (e.g. for RSA, the PKCS#1 standard - see the OS2IP conversion function). In RSA, the byte string is read as a big endian number in base 256. For example, the byte string 0x01 0x02 is interpreted as the number 258 (256 * 1 + 2).

|improve this answer|||||
$\endgroup$
3
$\begingroup$

Each character has a value assigned to it. If the encoding is ASCII, the letter s is stored inside the computer as the 8-bit binary value 01110011. The letter e is stored as the 8-bit value 01100101. So the word "secret" (encoded with ASCII) is converted to 01110011 01100101 01100011 01110010 01100101 01110100.

In fact, there is no conversion happening, because "secret" is always stored in binary format inside the computer. When you type the letter s on your keyboard, the keyboard sends a bunch of electric impulses to the motherboard (something like 1 volt, 2 volts, 2 volts, 2 volts, 1 volt, 1 volt, 2 volts, 2 volts).

Similarly, there is no conversion happening from the binary format 01110011 to the decimal format 115, because numbers are always stored in binary format (in a computer). We (humans) use the expression 115 to designate the 8-bit value 01110011 because it is easier to understand. The two notations are equivalent:

binary decimal
     0    0
     1    1
    10    2
    11    3
   100    4
   101    5
   110    6
   111    7
  1000    8
  1001    9
  1010   10
  1011   11
  1100   12
  1101   13
  1110   14
  1111   15
 10000   16
 10001   17
 10010   18
 10011   19
 10100   20
 10101   21
 10110   22
 10111   23
 11000   24
 11001   25
 11010   26
 11011   27
 11100   28
 11101   29
 11110   30
 11111   31
100000   32

Here is a link about counting in binary. Short version: when you count in binary, you do the same thing as usual, except that you forget the existence of the digits 2, 3, 4, 5, 6, 7, 8 and 9.

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.