Illegal Prime - Using The Numbers

Using The Numbers

Simply copying the decimal numbers from an electronic publication to a text file will typically result in a stream of bytes where each character (decimal digit or space) is encoded in one byte using the ASCII encoding. The particularity of these numbers is that, when written in base 2, the resulting stream of bits can also be interpreted as the content of a gzip or executable file. Converting such big numbers to base 2 and writing the resulting stream of bits to a file is a trivial process. Below is the source code of a go program that takes a number on the command line and writes a binary representation to the standard output.

package main import ( "math/big" "fmt" "os" "strings" ) func main { if len(os.Args) != 2 { fmt.Fprintf(os.Stderr, "Usage: %s \n", os.Args) os.Exit(1) } number_str := strings.Replace(os.Args, " ", "", -1) number, ok := new(big.Int).SetString(number_str, 0) if !ok { fmt.Fprintf(os.Stderr, "Failed to convert %q to big integer.\n", number_str) os.Exit(1) } os.Stdout.Write(number.Bytes) }

Given the appropriate numbers, this program will output the gzip and executable files described above.

Or as a VB.NET subroutine:

Sub Write_Binary_File_From_Large_Number(ByVal number As String, ByVal filename As String) Dim bigint As Numerics.BigInteger = Numerics.BigInteger.Parse(number.Replace(" ", String.Empty)) Dim byteArray As Byte = bigint.ToByteArray Array.Reverse(byteArray) File.WriteAllBytes(byteArray, filename); End Sub

Read more about this topic:  Illegal Prime

Famous quotes containing the word numbers:

    “The principle of majority rule is the mildest form in which the force of numbers can be exercised. It is a pacific substitute for civil war in which the opposing armies are counted and the victory is awarded to the larger before any blood is shed. Except in the sacred tests of democracy and in the incantations of the orators, we hardly take the trouble to pretend that the rule of the majority is not at bottom a rule of force.”
    —Walter Lippmann (1889–1974)