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 barriers of conventionality have been raised so high, and so strangely cemented by long existence, that the only hope of overthrowing them exists in the union of numbers linked together by common opinion and effort ... the united watchword of thousands would strike at the foundation of the false system and annihilate it.
    Mme. Ellen Louise Demorest 1824–1898, U.S. women’s magazine editor and woman’s club movement pioneer. Demorest’s Illustrated Monthly and Mirror of Fashions, p. 203 (January 1870)