Skip to content

Instantly share code, notes, and snippets.

@jhoughjr
Created August 15, 2024 02:27
Show Gist options
  • Save jhoughjr/d61bb43d09f4bf658b304aea487ec249 to your computer and use it in GitHub Desktop.
Save jhoughjr/d61bb43d09f4bf658b304aea487ec249 to your computer and use it in GitHub Desktop.
import Foundation
/// war cant of mars
// Assuming MSB first
let cant =
"""
0111011101100001011100100111011
0100110101101001011011100110010000100000011100100110010101100011011001010111000001110100011011110111001001110011001000000111011101101001011101000110111001100101011100110111001100100000011001110110110001101111011100100111100100100000011001100111001001101111011011010010000001110100011010000110010100100000011000100111010101110010011011100110100101101110011001110010000001101111011001100010000001110100011010000110010100100000011001100110110001100001011011010110010100001010010101000110100001100101001000000110011001101001011100100110010101110011001000000110111101100110001000000111010001101000011001010010000001100110011011110111001001100111011001010010000001100001011100100110010100100000011011000110100101101011011001010010000001110100011010000110010100100000011101000111001001110101011011010111000001100101011101000111001100100000011101110110100001101001011000110110100000100000011100000111001001101111011000110110110001100001011010010110110100001010010011110111010101110010001000000110010101101110011001110110100101101110011001010111001100100000011000010111010000100000011001100111010101101100011011000010000001110000011011110111011101100101011100100010110000100000011110010110111101110101011100100010000001100100011001010111001101110100011100100111010101100011011101000110100101101111011011100010000001101001011100110010000001101111011101010111001000100000011000010110100101101101000010100100111101110101011100100010000001010100011100100111010101110100011010000010000001101000011000010111001100100000011000110110111101101101011001010010000001101111011011100110110001101001011011100110010100001010000010100100010101101110011001110110000101100111011001010010000001110100011010000110010100100000011011000110100101101110011010110110000101100111011001010010110000100000010011110110110101101110011010010111001101110011011010010110000101101000001000000010100001011000001100110010100100001010010011110111010101110010001000000101010001110010011101010111010001101000001000000110100001100001011100110010000001100011011011110110110101100101001000000110111101101110011011000110100101101110011001010000101000001010010101110110100101110100011010000010000001101000011001010110000101110100001000000110000101101110011001000010000001101001011100100110111101101110001000000110000101101110011001000010000001101001011011100110010001110101011100110111010001110010011110010010000001110111011001010010011101101100011011000010000001110000011101010111001001100111011001010010000001111001011011110111010100100000011001100111001001101111011011010010000001110100011010000110100101110011001000000111011101101111011100100110110001100100000010100101100101101111011101010010000001110111011010010110110001101100001000000111001101110101011011100110010001100101011100100010110000100000011011010110010101101100011101000010110000100000011000010110111001100100001000000111001101101000011000010111010001110100011001010111001000100000011001100111001001101111011011010010000001110100011010000110010100100000011000100110111101101100011101000111001100100000011011110110011000100000011101110111001001100001011101000110100000100000011101110110010100100111011101100110010100100000011010000111010101110010011011000110010101100100000010100100000101101110011001000010000001110101011100000110111101101110001000000111100101101111011101010111001000100000011100100111010101101001011011100110010101100100001000000110010101101110011001000010110000100000011011110111010101110010001000000110001001101100011011110110111101100100001000000111001001100101011001000010000001100010011000010110111001101110011001010111001001110011001000000111001101110100011000010110111001100100001000000111010101101110011001100111010101110010011011000110010101100100000010100100111101110101011100100010000001001101011010010110011101101000011101000010000001101000011000010111001100100000011000110110111101101101011001010010000001101111011011100110110001101001011011100110010100001010000010100100010101101110011001110110000101100111011001010010000001110100011010000110010100100000011011000110100101101110011010110110000101100111011001010010110000100000010011110110110101101110011010010111001101110011011010010110000101101000001000000010100001011000001100110010100100001010010011110111010101110010001000000100110101101001011001110110100001110100001000000110100001100001011100110010000001100011011011110110110101100101001000000110111101101110011011000110100101101110011001010000101000001010010101000111001001100001011010010111010001101111011100100010110000100000010110000110010101101110011011110010110000100000010010000110010101110010011010010111010001100101011000110110100000101100001000000111010001101000011001010111100100100000011000010111001001100101001000000110000101110011001000000110111101101110011001010010000001110100011011110010000001110101011100110000101001010111011001010010000001110111011010010110110001101100001000000111001101100011011011110111001001100011011010000010000001110100011010000110010101101101001000000110011001110010011011110110110100100000011001010111100001101001011100110111010001100101011011100110001101100101001000000111011101101001011101000110100000100000011011110111010101110010001000000110010101101110011001110110100101101110011001010111001100100000011001000110010101110110011010010110111101110101011100110000101001001111011101010111001000100000011010000110000101110100011001010010000001100110011011110111001000100000011101000110100001100101011011010010000001100101011011100110001101101111011001000110010101100100001000000110100101101110011101000110111100100000011001010111011001100101011100100111100100100000011000100110111101101100011101000010000001100001011011100110010000100000011101000111001001110101011100110111001100001010010011110111010101110010001000000101011101110010011000010111010001101000001000000110100001100001011100110010000001100011011011110110110101100101001000000110111101101110011011000110100101101110011001010000101000001010010001010110111001100111011000010110011101100101001000000111010001101000011001010010000001101100011010010110111001101011011000010110011101100101001011000010000001001111011011010110111001101001011100110111001101101001011000010110100000100000001010000101100000110011001010010000101001001111011101010111001000100000010101110111001001100001011101000110100000100000011010000110000101110011001000000110001101101111011011010110010100100000011011110110111001101100011010010110111001100101000010100000101001010100011010010111010001100001011011100111001100100000011100110111010001110010011010010110010001101001011011100110011100100000011001100110111101110010011101110110000101110010011001000010110000100000010011110111001001100100011010010110111001100001011101000110100101101001001000000110001001111001001000000111010001101000011001010010000001110011011000110110111101110010011001010000101001010100011010000110010101111001001000000110000101110010011001010010000001100100011100100110111101110111011011100110100101101110011001110010000001101111011101010111010000100000011000100110110001100001011100110111000001101000011001010110110101100101011100100111001100100000001001110110111001100101011000010111010001101000001000000111010001101000011001010110100101110010001000000110011101110010011001010110000101110100001000000110110101100101011000110110100001100001011011100110100101100011001000000111001001101111011000010111001000001010010101000111001001100001011001000110100101110100011010010110111101101110001000000110100101110011001000000110111101110101011100100010000001100010011101010110110001110111011000010111001001101011001011000010000001101001011101000010000001100101011011100110010001110101011100100110010101110011001000000110011001101111011100100110010101110110011001010111001000100000011011010110111101110010011001010000101001001111011101010111001000100000010101100110100101100011011101000110111101110010011110010010000001100011011011110110110101100101011100110010000001101111011011100110110001101001011011100110010100001010000010100100010101101110011001110110000101100111011001010010000001110100011010000110010100100000011011000110100101101110011010110110000101100111011001010010110000100000010011110110110101101110011010010111001101110011011010010110000101101000001000000010100001011000001100110010100100001010010011110111010101110010001000000101011001101001011000110111010001101111011100100111100100100000011000110110111101101101011001010111001100100000011011110110111001101100011010010110111001100101000010100000101001000100011001010111010101110011001000000110010101110011011101000010000001101101011000010110001101101000011010010110111001100001001000000010100001011000001100110010100100001010010011010110000101100011011010000110100101101110011000010000101000001010010001010110111001100111011000010110011101100101001000000111010001101000011001010010000001101100011010010110111001101011011000010110011101100101001011000010000001001111011011010110111001101001011100110111001101101001011000010110100000100000001010000101100000110011001010010000101001001111011101010111001000100000010101100110100101100011011101000110111101110010011110010010000001100011011011110110110101100101011100110010000001101111011011100110110001101001011011100110010
0111011101100001011100100111011
"""
func toAscii() -> String {
let chunkSize = 8
let bytes = cant.count / chunkSize
print("data is \(bytes) bytes in a string \(cant.count) chars long")
var output = ""
var bytesProcessed = 0
let data = cant.data(using: .utf8)!
for byteIndex in stride(from: 0, through: cant.count+1, by: chunkSize) {
let b1 = data[byteIndex]
let b2 = data[byteIndex+1]
let b3 = data[byteIndex+2]
let b4 = data[byteIndex+3]
let b5 = data[byteIndex+4]
let b6 = data[byteIndex+5]
let b7 = data[byteIndex+6]
let b8 = data[byteIndex+7]
var thisByte = stringBitsToByte(bits: [b1,b2,b3,b4,b5,b6,b7,b8])
output.append(String(cString: &thisByte))
bytesProcessed += 1
}
return output
}
func stringBitsToByte(bits: [UInt8]) -> UInt8 {
return 0
}
print(toAscii())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment