forked from barryclark/jekyll-now
-
Notifications
You must be signed in to change notification settings - Fork 5
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
7 changed files
with
331 additions
and
33 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
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
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,30 @@ | ||
# Overview | ||
|
||
The game is split into three parts. | ||
|
||
- the core logic of the game (implemented in rust) | ||
- the frontend (implemented in flask) | ||
- the RL agent (implemented in python / jax) | ||
|
||
## Core logic | ||
|
||
Why did I implement the core logic in rust? | ||
Good question. | ||
|
||
I knew I wanted to do some reinforcement learning, so I wanted the core logic to be fast. | ||
I also wanted to learn rust. | ||
|
||
|
||
I have implemented the core game in rust with some small changes; | ||
|
||
- encryption is based on a 'simple' version of enimga. Aka, a 2 rotor polynumeric substitution cipher. | ||
- re-encryption now costs victory points | ||
- you can send as many or as few resources to a single battle as you like (rather than max 2). | ||
|
||
## Frontend | ||
|
||
|
||
|
||
## RL agent | ||
|
||
I have implemented a RL agent to play the game. |
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,154 @@ | ||
--- | ||
title: A tutorial on ciphers and enigma | ||
subtitle: "Code breaking" | ||
layout: post | ||
permalink: /turing-vs-scherbius/enigma/ | ||
categories: | ||
- "tutorial" | ||
--- | ||
|
||
|
||
<style> | ||
.small-input { | ||
width: 50px; | ||
} | ||
|
||
.large-input { | ||
width: 240px; | ||
font-size: 16px; | ||
} | ||
|
||
p { | ||
font-size: 16px; | ||
} | ||
</style> | ||
|
||
<!-- link to my easy enigma --> | ||
|
||
## Cesar Cipher | ||
|
||
Enter a string to see it shifted by <input type="number" id="inputK" value="3" placeholder=3 class="small-input"> positions: | ||
|
||
<div> | ||
<input type="text" id="inputTextCesar" placeholder="Enter text here" onkeypress="checkEnterCesar(event)"> | ||
</div> | ||
<p>Shifted Text: <span id="shiftedText"></span></p> | ||
|
||
<script> | ||
function checkEnterCesar(event) { | ||
if (event.key === 'Enter') { | ||
const input = document.getElementById('inputTextCesar').value; | ||
const shift = parseInt(document.getElementById('inputK').value); | ||
let shiftedText = shiftCipher(input, shift); | ||
document.getElementById('shiftedText').innerText = shiftedText; | ||
} | ||
} | ||
|
||
function shiftCipher(input, shift) { | ||
// assume only lower case | ||
const alphabet = 'abcdefghijklmnopqrstuvwxyz'; | ||
|
||
let shiftedText = ''; | ||
|
||
for (let i = 0; i < input.length; i++) { | ||
const char = input[i]; | ||
const index = alphabet.indexOf(char); | ||
if (index === -1) { | ||
shiftedText += char; | ||
continue; | ||
} else { | ||
const newIndex = (index + shift) % 26; | ||
shiftedText += alphabet[newIndex]; | ||
} | ||
} | ||
return shiftedText; | ||
} | ||
|
||
</script> | ||
|
||
|
||
|
||
## Substitution cipher | ||
|
||
An arbitrary permutation of the alphabet. | ||
|
||
<div> | ||
abcdefghijklmnopqrstuvwxyz<br> | ||
<input type="text" id="inputSubstitution" placeholder="trialbcdefghjkmnopqrsuvwxyz" value="trialbcdefghjkmnopqrsuvwxyz" class="large-input"> | ||
</div> | ||
|
||
<div> | ||
<input type="text" id="inputTextSubstitution" placeholder="Enter text here" onkeypress="checkEnterSubstitution(event)"> | ||
</div> | ||
|
||
<p>Substituted Text: <span | ||
id="substitutedText"></span></p> | ||
|
||
<script> | ||
function checkEnterSubstitution(event) { | ||
if (event.key === 'Enter') { | ||
const input = document.getElementById('inputTextSubstitution').value; | ||
const substitution = document.getElementById('inputSubstitution').value; | ||
let result = substitutionCipher(input, substitution); | ||
document.getElementById('substitutedText').innerText = result; | ||
} | ||
} | ||
|
||
function substitutionCipher(input, substitution) { | ||
// assume only lower case | ||
const alphabet = 'abcdefghijklmnopqrstuvwxyz'; | ||
|
||
// if first letter of substitution is 't', then 'a' is replaced with 't' | ||
|
||
let result = ''; | ||
|
||
for (let i = 0; i < input.length; i++) { | ||
const char = input[i]; | ||
const index = substitution.indexOf(char); | ||
if (index === -1) { | ||
result += char; | ||
continue; | ||
} else { | ||
result += alphabet[index]; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
</script> | ||
|
||
|
||
### A stepping substitution cipher | ||
|
||
This is a simple substitution cipher where the substitution changes every time a letter is used. | ||
|
||
<div> | ||
<input type="text" id="inputSteppingSubstitution" placeholder="trialbcdefghjkmnopqrsuvwxyz" value="trialbcdefghjkmnopqrsuvwxyz" class="large-input"> | ||
<p>Stepper:<span id="counter"></span></p> | ||
</div> | ||
|
||
<div> | ||
<input type="text" id="inputTextStepping" placeholder="Enter text here" onkeypress="checkEnterStepping(event)"> | ||
</div> | ||
|
||
<p>Stepping Substituted Text: <span id="steppingSubstitutedText"></span></p> | ||
|
||
<script> | ||
let counter = 0; | ||
document.getElementById('counter').innerText = counter; | ||
function checkEnterStepping(event) { | ||
if (event.key === 'Enter') { | ||
counter += 1; | ||
document.getElementById('counter').innerText = counter; | ||
|
||
const input = document.getElementById('inputTextStepping').value; | ||
const substitution = document.getElementById('inputSteppingSubstitution').value; | ||
let result = substitutionCipher(input, substitution); | ||
document.getElementById('steppingSubstitutedText').innerText = result; | ||
|
||
// update the substitution by shifting it by one | ||
let updated_sub = shiftCipher(substitution, 1); | ||
document.getElementById('inputSteppingSubstitution').value = updated_sub; | ||
} | ||
} | ||
</script> |
Oops, something went wrong.