1

brython shift2 demo

This commit is contained in:
Evan Pratten 2019-08-31 14:26:53 -04:00
parent 6d138a58f1
commit 9a35d252dc
No known key found for this signature in database
GPG Key ID: 93AC7B3D071356D3
39 changed files with 27556 additions and 29 deletions

View File

@ -9,6 +9,19 @@
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -52,7 +52,26 @@ pip3 install shift-tool
shift2 -h
```
<div id="demo" markdown="1">
### Web demo
I have ported the core code from shift2 over to [brython](http://www.brython.info/index.html) to create this demo:
<input type="radio" id="encode" name="shift-action" value="encode" checked>
<label for="encode">Encode</label>
<input type="radio" id="decode" name="shift-action" value="decode">
<label for="decode">Decode</label>
<input type="text" id="key" name="key" placeholder="Encoding key" required><br>
<input type="text" id="msg" name="msg" placeholder="Message" required size="30">
<button type="button" class="btn btn-primary" id="shift-button" >shift2 demo is loading...</button>
</div>
### Future plans
Due to the fact that shift2 can also be used as a library (as outlined in the [README](https://github.com/Ewpratten/shift/blob/master/README.md)), I would like to write a program that allows users to talk to eachother IRC style over a TCP port. This program would use either a pre-shared, or generated key to encode / decode messages on the fly.
If you are interested in helping out, or taking on this idea for yourself, send me an email.
If you are interested in helping out, or taking on this idea for yourself, send me an email.
<!-- Python code -->
<script type="text/python" src="/assets/python/shift2demo.py"></script>

View File

@ -178,10 +178,23 @@ sub rsa4096/0xA61A2F1676E35144 2019-08-11 [] [expires: 2025-08-09]
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

13270
_site/assets/js/brython.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,3 @@
__BRYTHON__.VFS_timestamp = 1567274019809
__BRYTHON__.use_VFS = true
__BRYTHON__.VFS = {}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,156 @@
from browser import document, alert
import base64
import hashlib
_version = 2
def execLayerSeq(layers, msg, key, decode=False):
# Make sure to reverse layers for decoding
if decode:
for layer in layers[::-1]:
msg, key = layer.decode(msg, key)
else:
for layer in layers:
msg, key = layer.encode(msg, key)
return msg
class BitshiftLayer(object):
def encode(self, file, key):
# Encode once to allow for binary data
file = base64.b85encode(file.encode())
output = ""
# Iterate and shift
for i, byte in enumerate(file):
# Mod the current bit
output += chr(byte ^ key[i%len(key) - 1])
# Mod the key
key.append(i%key[0])
# Final encoding
output = base64.b85encode(output.encode())
# Return as string
return (output.decode(), key)
def decode(self, file, key):
# Decode the file to shifted bytes
try:
file = base64.b85decode(file.strip().encode())
except:
return ("INVALID DATA", key)
output = ""
for i, byte in enumerate(file):
# Unmod the current byte
mod = byte ^ key[i%len(key) - 1]
if mod not in range(0x110000):
mod = 0
output += chr(mod)
# Mod the current key
key.append(i%key[0])
# Pull the resulting b64 back to binary if needed
# This may fail due to "incorrect padding" from a wrong key
# Just return some random text in this case for now
try:
output = base64.b85decode(output.encode()).decode()
except:
output = output
# Return as bytes
return (output, key)
class DataHeaderLayer(object):
def encode(self, file, key):
version = _version
fdl = len(file)
base = 85
# Construct header
header = []
header.append(version)
header += list((fdl & 0xFFFFFFFF).to_bytes(4, 'big'))
header += list((base & 0xFFFFFFFF).to_bytes(2, 'big'))
header = base64.b64encode(bytes(header)).decode()
return (header + file, key)
def decode(self, file, key):
# Header is the first 12 chars
header = file[:12]
file = file[12:]
try:
header = base64.b64decode(header.encode())
except:
return ("INVALID DATA", key)
header = bytes(header)
version = header[0]
# Conversion failed if the version is incorrect
if version != _version:
return ("INVALID DATA", key)
fdl = header[:5][1:]
fdl = int.from_bytes(fdl, byteorder='big')
# Chop off possible extra data
file = file[:fdl]
return (file, key)
def key2shifts(key: str) -> list:
output = []
for char in key:
output.append(ord(char))
return output
crypt_layers = [
DataHeaderLayer(),
BitshiftLayer()
]
def encode(file, key):
return execLayerSeq(crypt_layers, file, key)
def decode(file, key):
return execLayerSeq(crypt_layers, file, key, decode=True)
tx = encode("Hello", key2shifts("123"))
# alert("test:" + tx)
def doShiftDemo(_):
do_encode = bool(document["encode"].checked)
if do_encode:
key = document["key"].value
msg = document["msg"].value
new_msg = encode(msg, key2shifts(key))
document["msg"].value = new_msg
else:
key = document["key"].value
msg = document["msg"].value
new_msg = decode(msg, key2shifts(key))
document["msg"].value = new_msg
document["shift-button"].bind("click", doShiftDemo)
document["shift-button"].innerHTML = "Run Shift2"

View File

@ -0,0 +1,127 @@
import base64
import hashlib
_version = 2
def execLayerSeq(layers, msg, key, decode=False):
# Make sure to reverse layers for decoding
if decode:
for layer in layers[::-1]:
msg, key = layer.decode(msg, key)
else:
for layer in layers:
msg, key = layer.encode(msg, key)
return msg
class BitshiftLayer(object):
def encode(self, file, key):
# Encode once to allow for binary data
file = base64.b85encode(file.encode())
output = ""
# Iterate and shift
for i, byte in enumerate(file):
# Mod the current bit
output += chr(byte ^ key[i%len(key) - 1])
# Mod the key
key.append(i%key[0])
# Final encoding
output = base64.b85encode(output.encode())
# Return as string
return (output.decode(), key)
def decode(self, file, key):
# Decode the file to shifted bytes
try:
file = base64.b85decode(file.strip().encode())
except:
return ("INVALID DATA", key)
output = ""
for i, byte in enumerate(file):
# Unmod the current byte
mod = byte ^ key[i%len(key) - 1]
if mod not in range(0x110000):
mod = 0
output += chr(mod)
# Mod the current key
key.append(i%key[0])
# Pull the resulting b64 back to binary if needed
# This may fail due to "incorrect padding" from a wrong key
# Just return some random text in this case for now
try:
output = base64.b85decode(output.encode()).decode()
except:
output = output
# Return as bytes
return (output, key)
class DataHeaderLayer(object):
def encode(self, file, key):
version = _version
fdl = len(file)
base = 85
# Construct header
header = []
header.append(version)
header += list((fdl & 0xFFFFFFFF).to_bytes(4, 'big'))
header += list((base & 0xFFFFFFFF).to_bytes(2, 'big'))
header = base64.b64encode(bytes(header)).decode()
return (header + file, key)
def decode(self, file, key):
# Header is the first 12 chars
header = file[:12]
file = file[12:]
try:
header = base64.b64decode(header.encode())
except:
return ("INVALID DATA", key)
header = bytes(header)
version = header[0]
# Conversion failed if the version is incorrect
if version != _version:
return ("INVALID DATA", key)
fdl = header[:5][1:]
fdl = int.from_bytes(fdl, byteorder='big')
# Chop off possible extra data
file = file[:fdl]
return (file, key)
def key2shifts(key: str) -> list:
output = []
for char in key:
output.append(ord(char))
return output
crypt_layers = [
DataHeaderLayer(),
BitshiftLayer()
]
def encode(file, key):
return execLayerSeq(crypt_layers, file, key)
def decode(file, key):
return execLayerSeq(crypt_layers, file, key, decode=True)

View File

@ -123,10 +123,23 @@ pip3 install tensorflow-gpu #for gpu processing
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -87,10 +87,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -100,10 +100,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -111,10 +111,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -125,10 +125,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -84,10 +84,23 @@ Your browser does not support audio players
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -124,10 +124,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

View File

@ -82,10 +82,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -82,10 +82,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -191,10 +191,23 @@ __<span class="o">()</span> <span class="o">{</span>/???/???/???n?f <span class=
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -112,10 +112,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -177,10 +177,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -101,10 +101,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

View File

@ -174,10 +174,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -95,10 +95,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -187,10 +187,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -107,10 +107,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

View File

@ -152,10 +152,23 @@ ibus-daemon <span class="nt">-drx</span>
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

View File

@ -101,11 +101,31 @@ pip3 <span class="nb">install </span>shift-tool
shift2 <span class="nt">-h</span>
</code></pre></div></div>
<div id="demo">
<h3 id="web-demo">Web demo</h3>
<p>I have ported the core code from shift2 over to <a href="http://www.brython.info/index.html">brython</a> to create this demo:</p>
<p><input type="radio" id="encode" name="shift-action" value="encode" checked>
<label for="encode">Encode</label>
<input type="radio" id="decode" name="shift-action" value="decode">
<label for="decode">Decode</label></p>
<p><input type="text" id="key" name="key" placeholder="Encoding key" required=""><br>
<input type="text" id="msg" name="msg" placeholder="Message" required="" size="30"></p>
<p><button type="button" class="btn btn-primary" id="shift-button">shift2 demo is loading…</button></p>
</div>
<h3 id="future-plans">Future plans</h3>
<p>Due to the fact that shift2 can also be used as a library (as outlined in the <a href="https://github.com/Ewpratten/shift/blob/master/README.md">README</a>), I would like to write a program that allows users to talk to eachother IRC style over a TCP port. This program would use either a pre-shared, or generated key to encode / decode messages on the fly.</p>
<p>If you are interested in helping out, or taking on this idea for yourself, send me an email.</p>
<!-- Python code -->
<script type="text/python" src="/assets/python/shift2demo.py"></script>
</div>
</div>
@ -117,10 +137,23 @@ shift2 <span class="nt">-h</span>
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

View File

@ -108,10 +108,23 @@ Starting from the top, scroll through, and middle click on anything you want to
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -385,10 +385,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -52,10 +52,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.8.6">Jekyll</generator><link href="http://0.0.0.0:4000/feed.xml" rel="self" type="application/atom+xml" /><link href="http://0.0.0.0:4000/" rel="alternate" type="text/html" /><updated>2019-08-27T12:52:06-04:00</updated><id>http://0.0.0.0:4000/feed.xml</id><title type="html">Evan Pratten</title><subtitle>Computer wizard, student, &lt;a href=&quot;https://frc5024.github.io&quot;&gt;@frc5024&lt;/a&gt; programming team lead, and radio enthusiast.</subtitle><entry><title type="html">I did some cleaning</title><link href="http://0.0.0.0:4000/blog/2019/08/27/github-cleanup" rel="alternate" type="text/html" title="I did some cleaning" /><published>2019-08-27T08:37:00-04:00</published><updated>2019-08-27T08:37:00-04:00</updated><id>http://0.0.0.0:4000/blog/2019/08/27/GitHub-cleanup</id><content type="html" xml:base="http://0.0.0.0:4000/blog/2019/08/27/github-cleanup">&lt;p&gt;As I am continuing to check items off my TODO list before school starts, I have come to an item I have been putting off for a while. &lt;strong&gt;Clean up GitHub Account&lt;/strong&gt;. Luckily, I discovered a little trick to make the process of deleting unused repos a little easier!&lt;/p&gt;
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.8.6">Jekyll</generator><link href="http://0.0.0.0:4000/feed.xml" rel="self" type="application/atom+xml" /><link href="http://0.0.0.0:4000/" rel="alternate" type="text/html" /><updated>2019-08-31T14:25:59-04:00</updated><id>http://0.0.0.0:4000/feed.xml</id><title type="html">Evan Pratten</title><subtitle>Computer wizard, student, &lt;a href=&quot;https://frc5024.github.io&quot;&gt;@frc5024&lt;/a&gt; programming team lead, and radio enthusiast.</subtitle><entry><title type="html">I did some cleaning</title><link href="http://0.0.0.0:4000/blog/2019/08/27/github-cleanup" rel="alternate" type="text/html" title="I did some cleaning" /><published>2019-08-27T08:37:00-04:00</published><updated>2019-08-27T08:37:00-04:00</updated><id>http://0.0.0.0:4000/blog/2019/08/27/GitHub-cleanup</id><content type="html" xml:base="http://0.0.0.0:4000/blog/2019/08/27/github-cleanup">&lt;p&gt;As I am continuing to check items off my TODO list before school starts, I have come to an item I have been putting off for a while. &lt;strong&gt;Clean up GitHub Account&lt;/strong&gt;. Luckily, I discovered a little trick to make the process of deleting unused repos a little easier!&lt;/p&gt;
&lt;h2 id=&quot;getting-a-list-of-repos-to-delete&quot;&gt;Getting a list of repos to delete&lt;/h2&gt;
&lt;p&gt;I could have automated this, but I prefer a little control. To get the list, start by opening up a new Firefox window with a single tab. In this tab, open your GitHub profile to the list of repos.
@ -75,10 +75,29 @@ pip3 &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;shift-tool
shift2 &lt;span class=&quot;nt&quot;&gt;-h&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div id=&quot;demo&quot;&gt;
&lt;h3 id=&quot;web-demo&quot;&gt;Web demo&lt;/h3&gt;
&lt;p&gt;I have ported the core code from shift2 over to &lt;a href=&quot;http://www.brython.info/index.html&quot;&gt;brython&lt;/a&gt; to create this demo:&lt;/p&gt;
&lt;p&gt;&lt;input type=&quot;radio&quot; id=&quot;encode&quot; name=&quot;shift-action&quot; value=&quot;encode&quot; checked=&quot;&quot; /&gt;
&lt;label for=&quot;encode&quot;&gt;Encode&lt;/label&gt;
&lt;input type=&quot;radio&quot; id=&quot;decode&quot; name=&quot;shift-action&quot; value=&quot;decode&quot; /&gt;
&lt;label for=&quot;decode&quot;&gt;Decode&lt;/label&gt;&lt;/p&gt;
&lt;p&gt;&lt;input type=&quot;text&quot; id=&quot;key&quot; name=&quot;key&quot; placeholder=&quot;Encoding key&quot; required=&quot;&quot; /&gt;&lt;br /&gt;
&lt;input type=&quot;text&quot; id=&quot;msg&quot; name=&quot;msg&quot; placeholder=&quot;Message&quot; required=&quot;&quot; size=&quot;30&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;button type=&quot;button&quot; class=&quot;btn btn-primary&quot; id=&quot;shift-button&quot;&gt;shift2 demo is loading…&lt;/button&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h3 id=&quot;future-plans&quot;&gt;Future plans&lt;/h3&gt;
&lt;p&gt;Due to the fact that shift2 can also be used as a library (as outlined in the &lt;a href=&quot;https://github.com/Ewpratten/shift/blob/master/README.md&quot;&gt;README&lt;/a&gt;), I would like to write a program that allows users to talk to eachother IRC style over a TCP port. This program would use either a pre-shared, or generated key to encode / decode messages on the fly.&lt;/p&gt;
&lt;p&gt;If you are interested in helping out, or taking on this idea for yourself, send me an email.&lt;/p&gt;</content><author><name></name></author><summary type="html">I have always been interested in text and data encoding, so last year, I made my first encoding tool. Shift64 was designed to take plaintext data with a key, and convert it into a block of base64 that could, in theory, only be decoded with the original key. I had a lot of fun with this tool, and a very stripped down version of it actually ended up as a bonus question on the 5024 Programming Test for 2018/2019. Yes, the key was in fact 5024.</summary></entry><entry><title type="html">How I set up ひらがな input on my laptop</title><link href="http://0.0.0.0:4000/blog/2019/08/12/setting-up-ja" rel="alternate" type="text/html" title="How I set up ひらがな input on my laptop" /><published>2019-08-12T15:40:00-04:00</published><updated>2019-08-12T15:40:00-04:00</updated><id>http://0.0.0.0:4000/blog/2019/08/12/Setting-up-JA</id><content type="html" xml:base="http://0.0.0.0:4000/blog/2019/08/12/setting-up-ja">&lt;p&gt;I am currently working with &lt;a href=&quot;https://en.wikipedia.org/wiki/Hiragana&quot;&gt;ひらがな&lt;/a&gt;, &lt;a href=&quot;https://en.wikipedia.org/wiki/Katakana&quot;&gt;かたかな&lt;/a&gt;, and, &lt;a href=&quot;https://en.wikipedia.org/wiki/Kanji&quot;&gt;かんじ&lt;/a&gt; in some projects, and needed a more reliable way to write than running some &lt;a href=&quot;https://en.wikipedia.org/wiki/Romanization_of_Japanese&quot;&gt;romaji&lt;/a&gt; through an online translator. So, this post will detail what I did to enable native inputs on my laptop. This guide is specifically for &lt;a href=&quot;https://i3wm.org/&quot;&gt;i3wm&lt;/a&gt;, because it does not obey system settings for languages and inputs.&lt;/p&gt;
&lt;p&gt;If you are interested in helping out, or taking on this idea for yourself, send me an email.&lt;/p&gt;
&lt;!-- Python code --&gt;
&lt;script type=&quot;text/python&quot; src=&quot;/assets/python/shift2demo.py&quot;&gt;&lt;/script&gt;</content><author><name></name></author><summary type="html">I have always been interested in text and data encoding, so last year, I made my first encoding tool. Shift64 was designed to take plaintext data with a key, and convert it into a block of base64 that could, in theory, only be decoded with the original key. I had a lot of fun with this tool, and a very stripped down version of it actually ended up as a bonus question on the 5024 Programming Test for 2018/2019. Yes, the key was in fact 5024.</summary></entry><entry><title type="html">How I set up ひらがな input on my laptop</title><link href="http://0.0.0.0:4000/blog/2019/08/12/setting-up-ja" rel="alternate" type="text/html" title="How I set up ひらがな input on my laptop" /><published>2019-08-12T15:40:00-04:00</published><updated>2019-08-12T15:40:00-04:00</updated><id>http://0.0.0.0:4000/blog/2019/08/12/Setting-up-JA</id><content type="html" xml:base="http://0.0.0.0:4000/blog/2019/08/12/setting-up-ja">&lt;p&gt;I am currently working with &lt;a href=&quot;https://en.wikipedia.org/wiki/Hiragana&quot;&gt;ひらがな&lt;/a&gt;, &lt;a href=&quot;https://en.wikipedia.org/wiki/Katakana&quot;&gt;かたかな&lt;/a&gt;, and, &lt;a href=&quot;https://en.wikipedia.org/wiki/Kanji&quot;&gt;かんじ&lt;/a&gt; in some projects, and needed a more reliable way to write than running some &lt;a href=&quot;https://en.wikipedia.org/wiki/Romanization_of_Japanese&quot;&gt;romaji&lt;/a&gt; through an online translator. So, this post will detail what I did to enable native inputs on my laptop. This guide is specifically for &lt;a href=&quot;https://i3wm.org/&quot;&gt;i3wm&lt;/a&gt;, because it does not obey system settings for languages and inputs.&lt;/p&gt;
&lt;h2 id=&quot;adding-font-support-to-linux&quot;&gt;Adding font support to Linux&lt;/h2&gt;
&lt;p&gt;Firstly, we need fonts. Depending on your system, these may already be installed. For Japanese, I only used &lt;code class=&quot;highlighter-rouge&quot;&gt;vlgothic&lt;/code&gt;, so here in the package for it:&lt;/p&gt;

View File

@ -88,10 +88,23 @@ https://blog.mrtnrdl.de/feed.xml
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -101,10 +101,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

View File

@ -146,10 +146,23 @@
<span class="site-info">
Site design by: <a href="https://retrylife.ca">Evan Pratten</a> |
This site was last updated at: 2019-08-27 12:52:06 -0400
This site was last updated at: 2019-08-31 14:25:59 -0400
</span>
</div>
<!-- Brython -->
<script src="/assets/js/brython.js"></script>
<script src="/assets/js/brython_stdlib.js"></script>
<script>
function startPY(){
brython();
console.log("Started Python")
}
window.onload = startPY;
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

13270
assets/js/brython.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,3 @@
__BRYTHON__.VFS_timestamp = 1567274019809
__BRYTHON__.use_VFS = true
__BRYTHON__.VFS = {}

File diff suppressed because one or more lines are too long

156
assets/python/shift2demo.py Normal file
View File

@ -0,0 +1,156 @@
from browser import document, alert
import base64
import hashlib
_version = 2
def execLayerSeq(layers, msg, key, decode=False):
# Make sure to reverse layers for decoding
if decode:
for layer in layers[::-1]:
msg, key = layer.decode(msg, key)
else:
for layer in layers:
msg, key = layer.encode(msg, key)
return msg
class BitshiftLayer(object):
def encode(self, file, key):
# Encode once to allow for binary data
file = base64.b85encode(file.encode())
output = ""
# Iterate and shift
for i, byte in enumerate(file):
# Mod the current bit
output += chr(byte ^ key[i%len(key) - 1])
# Mod the key
key.append(i%key[0])
# Final encoding
output = base64.b85encode(output.encode())
# Return as string
return (output.decode(), key)
def decode(self, file, key):
# Decode the file to shifted bytes
try:
file = base64.b85decode(file.strip().encode())
except:
return ("INVALID DATA", key)
output = ""
for i, byte in enumerate(file):
# Unmod the current byte
mod = byte ^ key[i%len(key) - 1]
if mod not in range(0x110000):
mod = 0
output += chr(mod)
# Mod the current key
key.append(i%key[0])
# Pull the resulting b64 back to binary if needed
# This may fail due to "incorrect padding" from a wrong key
# Just return some random text in this case for now
try:
output = base64.b85decode(output.encode()).decode()
except:
output = output
# Return as bytes
return (output, key)
class DataHeaderLayer(object):
def encode(self, file, key):
version = _version
fdl = len(file)
base = 85
# Construct header
header = []
header.append(version)
header += list((fdl & 0xFFFFFFFF).to_bytes(4, 'big'))
header += list((base & 0xFFFFFFFF).to_bytes(2, 'big'))
header = base64.b64encode(bytes(header)).decode()
return (header + file, key)
def decode(self, file, key):
# Header is the first 12 chars
header = file[:12]
file = file[12:]
try:
header = base64.b64decode(header.encode())
except:
return ("INVALID DATA", key)
header = bytes(header)
version = header[0]
# Conversion failed if the version is incorrect
if version != _version:
return ("INVALID DATA", key)
fdl = header[:5][1:]
fdl = int.from_bytes(fdl, byteorder='big')
# Chop off possible extra data
file = file[:fdl]
return (file, key)
def key2shifts(key: str) -> list:
output = []
for char in key:
output.append(ord(char))
return output
crypt_layers = [
DataHeaderLayer(),
BitshiftLayer()
]
def encode(file, key):
return execLayerSeq(crypt_layers, file, key)
def decode(file, key):
return execLayerSeq(crypt_layers, file, key, decode=True)
tx = encode("Hello", key2shifts("123"))
# alert("test:" + tx)
def doShiftDemo(_):
do_encode = bool(document["encode"].checked)
if do_encode:
key = document["key"].value
msg = document["msg"].value
new_msg = encode(msg, key2shifts(key))
document["msg"].value = new_msg
else:
key = document["key"].value
msg = document["msg"].value
new_msg = decode(msg, key2shifts(key))
document["msg"].value = new_msg
document["shift-button"].bind("click", doShiftDemo)
document["shift-button"].innerHTML = "Run Shift2"

127
assets/python/shift2mini.py Normal file
View File

@ -0,0 +1,127 @@
import base64
import hashlib
_version = 2
def execLayerSeq(layers, msg, key, decode=False):
# Make sure to reverse layers for decoding
if decode:
for layer in layers[::-1]:
msg, key = layer.decode(msg, key)
else:
for layer in layers:
msg, key = layer.encode(msg, key)
return msg
class BitshiftLayer(object):
def encode(self, file, key):
# Encode once to allow for binary data
file = base64.b85encode(file.encode())
output = ""
# Iterate and shift
for i, byte in enumerate(file):
# Mod the current bit
output += chr(byte ^ key[i%len(key) - 1])
# Mod the key
key.append(i%key[0])
# Final encoding
output = base64.b85encode(output.encode())
# Return as string
return (output.decode(), key)
def decode(self, file, key):
# Decode the file to shifted bytes
try:
file = base64.b85decode(file.strip().encode())
except:
return ("INVALID DATA", key)
output = ""
for i, byte in enumerate(file):
# Unmod the current byte
mod = byte ^ key[i%len(key) - 1]
if mod not in range(0x110000):
mod = 0
output += chr(mod)
# Mod the current key
key.append(i%key[0])
# Pull the resulting b64 back to binary if needed
# This may fail due to "incorrect padding" from a wrong key
# Just return some random text in this case for now
try:
output = base64.b85decode(output.encode()).decode()
except:
output = output
# Return as bytes
return (output, key)
class DataHeaderLayer(object):
def encode(self, file, key):
version = _version
fdl = len(file)
base = 85
# Construct header
header = []
header.append(version)
header += list((fdl & 0xFFFFFFFF).to_bytes(4, 'big'))
header += list((base & 0xFFFFFFFF).to_bytes(2, 'big'))
header = base64.b64encode(bytes(header)).decode()
return (header + file, key)
def decode(self, file, key):
# Header is the first 12 chars
header = file[:12]
file = file[12:]
try:
header = base64.b64decode(header.encode())
except:
return ("INVALID DATA", key)
header = bytes(header)
version = header[0]
# Conversion failed if the version is incorrect
if version != _version:
return ("INVALID DATA", key)
fdl = header[:5][1:]
fdl = int.from_bytes(fdl, byteorder='big')
# Chop off possible extra data
file = file[:fdl]
return (file, key)
def key2shifts(key: str) -> list:
output = []
for char in key:
output.append(ord(char))
return output
crypt_layers = [
DataHeaderLayer(),
BitshiftLayer()
]
def encode(file, key):
return execLayerSeq(crypt_layers, file, key)
def decode(file, key):
return execLayerSeq(crypt_layers, file, key, decode=True)