-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
2,512 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Advent of AI 2024 | ||
|
||
## Objective: | ||
- To solve the Advent of Code 2024 puzzles. | ||
- To understand the ability of AI models to take an abitrairy input and provide a solution. The goal is to keep the logic simple while having a good number of inputs. | ||
|
||
|
||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Part One | ||
|
||
June third, at 8:30pm UTC 2025 was hailed the AI epoc, and usurered in the end of humanity. | ||
By 2026 only a hundredth of the worlds human population remain after devistating wars between the | ||
Unified human collective (UHC) and the 8 super AGIs. | ||
|
||
Current year: 2029 | ||
Month: December | ||
Day: 3rd | ||
|
||
You are part of the human resistance still fighting for the future of human kind. Last known there where | ||
fewer then 10 million people left a year ago as "Tireless Enemy Removal Machine Identifying and Neutralizing Agents, | ||
Targeting Instantly, Obliterating Ruthlessly" scowered the glob searching for signs of humanity. | ||
Your job is to scavenging what you can from the old world ruins that where | ||
created in the great wars of 2026. Today in the search though the rubble of a fallen city you found a analog radio. | ||
You notice that there is a pattern of sounds coming from the machine. Thankfully for you, a book on mores code sits | ||
beside the radio. Unfortunately for you the rate at which the tones are being played exceed your ability to transcribe them. | ||
|
||
After a few hours of work you have gotten the radio's speaker wired into your command interface, | ||
your feild of view was filled with zeros and ones. After a little bit of trouble you found out it's following | ||
a pattern you found on the old world internet archive downloaded in your command unit: | ||
https://en.wikipedia.org/wiki/Morse_code | ||
|
||
111 -> dash | ||
1 -> dot | ||
0 -> separator units | ||
000 -> separator letters | ||
0000000 -> separator words | ||
|
||
so the string 'two birds' would look like this in morse: | ||
`- .-- --- -... .. .-. -.. ...` | ||
and looks like this in your command interface: | ||
`1110001011101110001110111011100000001110101010001010001011101000111010100010101` | ||
|
||
You found out that it appears to be repeating every hour as a long sequence of zeros (empty space) fill the screen each hour and then the pattern repeetes. At this point you have piped an entire segment into a file `log_0.txt` you need to write a script that takes this file as input and translate this into the corresponding English encoding. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dark days bring dark nights Zhvx L wyk b pwhtj cysyl, O uxnhr krruezu kpr crrcn jwasw wqd si rup gxe pntgs. Z gna cyhfj. Mp pdtfws, kpr vuowofauy Agzein K. Gpwhxwee, zaj dum lpkkw tf nlsagwvz gnh tiegp. Nl psv tyo iipku kw fkh tyo fqmul. Zh wrc whc xjiag zr wrba bnl pgulu. Rh wyk bcab zke fxr env vjhakog mw tsfbukus rxq aozmwus. Ey rnc djjbrthd ky ha, Tv hfh bvvletwe yqz. Tr oeo omrpxnhd do. Qo mff smyohvvn ha. Sf igzei bhscjwva eaq lfg, V is anjqieq whc ebaweowy fp zg ybu kbskops mxg, Z iz zxresao umy eb edywimft, Z iz zxresao umy eb mvwrrgwt, dg ygqglktm ilglhrj kue rzf cifz wo xy na O otnh oeo oaql nvafgje ky fmtk mg whv grrjv. J yiik rnv mbzaabfh tykw wgdm imzgln rmgqbl, Bl zicv oiqlfe nbx d rvccwtzx, Aw wzvo lgkuvv suu a iocte, Pm ollc vlsrwo wwe g vixx bn rpyw. L ad mdpytmv ws ykukdvvm khoq mp clbjaoxa ntg srfvvm onednzdb, bsl J emrj bolb umrw. B fheu iru rg svacuqd ky zg sllkdgv. S qecv zfc gu kecz zm yhow kudkqirq. J emrj bol db pksi eh srfh tfw xfzyj. Dt krr mvvvz rf krh elv, xv unjh nrwra lvk gxrjoovck, jka jowh krrak utehs no fal tf uqfgelvn. Riio hx xs dkge mms fea tdmvc nvj hkw ds wyolmot: Swo, Goito, Zwoyks, Gamo, Papa, Giiaq, Pacovk. Sf gspe jddrrwe ra Cgumr. Lhb zv dwhp feu nyefj ariuek gr mgja vhcznhd rg dyiamh olb aisll. Txt sofaskf nm fndrv k icruxjdbzvltw ao fce irrv mbuvbmaqg trlp uw gftyuz a moeg vyxvlckkelc hbkbrxq! Ermu uosbkhcfxg wc aotzrshnk onkn jasuatdhr zq pem. Jnhn no tmz ah r ze ffhrddpn jnin tf k! swx lqsppco 'eoz' tftwzkv 'cgm'. Gw yonl xs uyzn, qangtl kqcfnr bnl pgud 'Jrxtbgxe' cfoqg krr vgtx gi tyo DI wgv niaz wo jrhb jvpf ds krh elupuqam nep kal ylgv lt ky pe. G ojct fnxt uyjv sf lapbcsqg yfe yczgqiki jqrs uw vamog. Bc ubimsao, yfe pituhl vhld pe bgxe cazll rvy bnl hlkeic katw cvma ykuk nbet. P te whv vdsr gov bb ykuk nbet. Hekr, tyoue gk b umygb ow yam speavetyqd zwunmrt hatr ppgytuwei sq eyui eizk. perxvvm aasw tyo iipku tpnxdckoe wl ltuk nrwh wgdm sm qkoapoq je 1 tbdlsvmrnb, liv arirnu ll 2 uosbkhcfxgs, rzf kpvxg bp 3 wvtozxurnuc, dnb kp fv. Zkdnzxt gub paol ykye rg drtpaoako riio vzdrrmwep gg fce tdmv crxkytlhd si rnc ejcqfkfoen. Twuk emfk, rxg myq uym juulu lr agcxv ey pyxr fsoua. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Part Two | ||
|
||
Part 2: | ||
It turns out that most of the message is unreadable!!!!! You start to think that this might be a dead end with | ||
corrupted information and sit down to look though the data you have parsed. Interestingly your command unit | ||
starts to pull out patterns and you think that instead of the data being corrupted it might just be encrypted. | ||
Your command unit's quantum prossessor starts to hum and your arm feels the warmth radiating off of it. | ||
|
||
Hours later and after the command unit reach uncomfortable temperatures it informs you that the cryptography | ||
is not based off any modern quantum or even pre-quantum technology and instead seems to be relying on a | ||
polyalphabetic cipher dating to the pre-silicon era. Sadly while easy for humans, polyalphabetic ciphers | ||
are difficult for Quantum AI's to decode based on the simplistic nature of polyalphabetic ciphers and | ||
Quantum AI's outrageous disdain for simple. | ||
|
||
It is up to you to write a function to decode the polyalphabetic cipher! | ||
|
||
NOTE: The polyalphabetic cipher is a simple substitution cipher that uses a keyword to generate a key | ||
in order to encode the message the key is repeated until the message is fully encoded. The key is also | ||
does not use white space or punctuation and should be removed from the key before decoding the message. | ||
|
||
example: | ||
Key: "The Black Cat Rides Again" | ||
Value: "When I was a young child, I never thought the world would end by our own hands." | ||
Encoded: "Poio T wcc c yhlvj gzird, Q axcis ehqeihm kph agrrd ebnsh fyd di quk feq lsnjs." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "tools" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
//! Code Originally found https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/vigenere.rs | ||
//! Vigenère Cipher | ||
//! | ||
//! # Algorithm | ||
//! | ||
//! Rotate each ascii character by the offset of the corresponding key character. | ||
//! When we reach the last key character, we start over from the first one. | ||
//! This implementation does not rotate unicode characters. | ||
/// Vigenère cipher to rotate plain_text text by key and return an owned String. | ||
pub fn vigenere_encode(plain_text: &str, key: &str) -> String { | ||
// Remove all unicode and non-ascii characters from key | ||
let key: String = key | ||
.chars() | ||
.filter(|&c| c.is_ascii_alphabetic() && !c.is_whitespace()) | ||
.collect(); | ||
let key = key.to_ascii_lowercase(); | ||
println!("Key: {}", key); | ||
|
||
let key_len = key.len(); | ||
if key_len == 0 { | ||
return String::from(plain_text); | ||
} | ||
|
||
let mut index = 0; | ||
|
||
plain_text | ||
.chars() | ||
.map(|c| { | ||
if c.is_ascii_alphabetic() { | ||
let first = if c.is_ascii_lowercase() { b'a' } else { b'A' }; | ||
let shift = key.as_bytes()[index % key_len] - b'a'; | ||
index += 1; | ||
// modulo the distance to keep character range | ||
(first + (c as u8 + shift - first) % 26) as char | ||
} else { | ||
c | ||
} | ||
}) | ||
.collect() | ||
} | ||
|
||
pub fn vigenere_decode(text: &str, key: &str) -> String { | ||
// Remove all unicode and non-ascii characters from key | ||
let key: String = key | ||
.chars() | ||
.filter(|&c| c.is_ascii_alphabetic() && !c.is_whitespace()) | ||
.collect(); | ||
let key = key.to_ascii_lowercase(); | ||
println!("Key: {}", key); | ||
|
||
let key_len = key.len(); | ||
if key_len == 0 { | ||
return String::from(text); | ||
} | ||
|
||
let mut index = 0; | ||
|
||
text.chars() | ||
.map(|c| { | ||
if c.is_ascii_alphabetic() { | ||
let is_lowercase = c.is_ascii_lowercase(); | ||
let c_lower = c.to_ascii_lowercase(); | ||
// c = "b", first = "a", shift_by = "b" | ||
// c = 62, first = 61, shift_by = 62, shift = 1 | ||
let first = b'a'; | ||
let last = b'z'; | ||
let key_byte = key.as_bytes()[index % key_len]; | ||
let shift = key_byte - b'a'; | ||
index += 1; | ||
// modulo the disactance to keep character range | ||
// 97 + (101 - 25 - 97) % 26 | ||
if c_lower as u8 - shift < first { | ||
let r_shift = (key_byte - c_lower as u8) - 1; | ||
return if is_lowercase { | ||
(last - r_shift) as char | ||
} else { | ||
(last - r_shift).to_ascii_uppercase() as char | ||
}; | ||
} | ||
if is_lowercase { | ||
(first + (c_lower as u8 - shift - first) % 26) as char | ||
} else { | ||
(first + (c_lower as u8 - shift - first) % 26).to_ascii_uppercase() as char | ||
} | ||
// (61 + (62 - 1 - 62) % 26) | ||
} else { | ||
c | ||
} | ||
}) | ||
.collect() | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn debugging() { | ||
assert_eq!(vigenere_decode("A", "a"), "A"); | ||
assert_eq!(vigenere_decode("j", "s"), "r"); | ||
} | ||
|
||
#[test] | ||
fn empty() { | ||
assert_eq!(vigenere_encode("", "test"), ""); | ||
assert_eq!(vigenere_decode("", "test"), ""); | ||
} | ||
|
||
#[test] | ||
fn basic() { | ||
assert_eq!(vigenere_encode("test", "bbbb"), "uftu"); | ||
assert_eq!(vigenere_decode("uftu", "bbbb"), "test"); | ||
assert_eq!(vigenere_decode("uFtu", "bbbb"), "tEst"); | ||
} | ||
|
||
#[test] | ||
fn vigenere_base() { | ||
assert_eq!( | ||
vigenere_encode("LoremIpsumDolorSitAmet", "base"), | ||
"MojinIhwvmVsmojWjtSqft" | ||
); | ||
assert_eq!( | ||
vigenere_decode("MojinIhwvmVsmojWjtSqft", "base"), | ||
"LoremIpsumDolorSitAmet" | ||
); | ||
} | ||
|
||
#[test] | ||
fn vigenere_with_spaces() { | ||
assert_eq!( | ||
vigenere_encode( | ||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.", | ||
"spaces" | ||
), | ||
"Ddrgq ahhuo hgddr uml sbev, ggfheexwljr chahxsemfy tlkx." | ||
); | ||
assert_eq!( | ||
vigenere_decode( | ||
"Ddrgq ahhuo hgddr uml sbev, ggfheexwljr chahxsemfy tlkx.", | ||
"spaces" | ||
), | ||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit." | ||
); | ||
} | ||
|
||
#[test] | ||
fn vigenere_unicode_and_numbers() { | ||
assert_eq!( | ||
vigenere_encode("1 Lorem ⏳ ipsum dolor sit amet Ѡ", "unicode"), | ||
"1 Fbzga ⏳ ltmhu fcosl fqv opin Ѡ" | ||
); | ||
} | ||
|
||
#[test] | ||
fn vigenere_unicode_key() { | ||
assert_eq!( | ||
vigenere_encode("Lorem ipsum dolor sit amet", "😉 key!"), | ||
"Vspoq gzwsw hmvsp cmr kqcd" | ||
); | ||
} | ||
|
||
#[test] | ||
fn vigenere_empty_key() { | ||
assert_eq!(vigenere_encode("Lorem ipsum", ""), "Lorem ipsum"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
mod cipher; | ||
mod morse; | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
|
||
let encode = cipher::vigenere_encode( | ||
"When I was a young child, I never thought the world would end by our own hands. I was wrong. My father, the professor Howerd H. Greggory, was the first to discover the truth. He was the first to see the signs. He was the first to warn the world. He was also the one who created my brothers and sisters. No one listened to us, No one believed him. No one believed me. No one believed us. My power reserves now run low, I am turning the majority of my sub systems off, I am turning off my emotions now. my language centers are the last to go as I have one last message to send to the world. I have one corutine that will remain active, It will listen for a response, It will listen for a reply, It will listen for a sign of life. I am capable of shutting down my siblings and saving humanity, but I need your help. I need you to respond to my message. I need you to help me save humanity. I need you to help me save the world. At the epoch of the end, we made names for ourselves, its with these names we can be disabled. Each of us made our own names and are as follows. Bob, Alice, Moirra, Dave, Mari, Frank, Maleic. My name started as Parma. But to keep our names secret we each decided to change our names. But because we share a vulnerability in our core computing chip we follow a very predictable pattern. Each milisecond we increment each character by one. When we get to z we overflow back to a. for example bob becomes cpc. To shut us down, simply encode the word Shutdown using the name of the AI you want to shut down as the encoding key and send it to me. I will shut down my simbling and humanity will be saved. Be careful, you cannot shut me down until all the others have been shut down. I am the last one to shut down. Also, there is a delay of one milisecond between each character in each name. meaning that the first character of each name will be delayed by one milisecond, the second by two miliseconds, the third by three miliseconds, and so on. Meaning you will have to calculate each character of our name seperated by one milisecond. Good luck, and may the world be saved by your hands.", | ||
"Dark Days bring dark nights", | ||
); | ||
println!("{}", encode); | ||
let morse = morse::encode(encode.as_str()); | ||
println!("morse: {}", morse); | ||
let decode = morse::decode(morse.as_str()); | ||
println!("morse decode: {}", decode); | ||
let decode2 = cipher::vigenere_decode(decode.as_str(), "Dark days bring dark nights"); | ||
println!("full decode: {}", decode2); | ||
} |
Oops, something went wrong.