brython shift2 demo
This commit is contained in:
parent
6d138a58f1
commit
9a35d252dc
@ -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"
|
||||
|
@ -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>
|
@ -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
13270
_site/assets/js/brython.js
Normal file
File diff suppressed because one or more lines are too long
3
_site/assets/js/brython_modules.js
Normal file
3
_site/assets/js/brython_modules.js
Normal file
@ -0,0 +1,3 @@
|
||||
__BRYTHON__.VFS_timestamp = 1567274019809
|
||||
__BRYTHON__.use_VFS = true
|
||||
__BRYTHON__.VFS = {}
|
3
_site/assets/js/brython_stdlib.js
Normal file
3
_site/assets/js/brython_stdlib.js
Normal file
File diff suppressed because one or more lines are too long
156
_site/assets/python/shift2demo.py
Normal file
156
_site/assets/python/shift2demo.py
Normal 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
_site/assets/python/shift2mini.py
Normal file
127
_site/assets/python/shift2mini.py
Normal 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)
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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>
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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>
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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, <a href="https://frc5024.github.io">@frc5024</a> 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"><p>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. <strong>Clean up GitHub Account</strong>. Luckily, I discovered a little trick to make the process of deleting unused repos a little easier!</p>
|
||||
<?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, <a href="https://frc5024.github.io">@frc5024</a> 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"><p>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. <strong>Clean up GitHub Account</strong>. Luckily, I discovered a little trick to make the process of deleting unused repos a little easier!</p>
|
||||
|
||||
<h2 id="getting-a-list-of-repos-to-delete">Getting a list of repos to delete</h2>
|
||||
<p>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 <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></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"><p>I am currently working with <a href="https://en.wikipedia.org/wiki/Hiragana">ひらがな</a>, <a href="https://en.wikipedia.org/wiki/Katakana">かたかな</a>, and, <a href="https://en.wikipedia.org/wiki/Kanji">かんじ</a> in some projects, and needed a more reliable way to write than running some <a href="https://en.wikipedia.org/wiki/Romanization_of_Japanese">romaji</a> through an online translator. So, this post will detail what I did to enable native inputs on my laptop. This guide is specifically for <a href="https://i3wm.org/">i3wm</a>, because it does not obey system settings for languages and inputs.</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></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"><p>I am currently working with <a href="https://en.wikipedia.org/wiki/Hiragana">ひらがな</a>, <a href="https://en.wikipedia.org/wiki/Katakana">かたかな</a>, and, <a href="https://en.wikipedia.org/wiki/Kanji">かんじ</a> in some projects, and needed a more reliable way to write than running some <a href="https://en.wikipedia.org/wiki/Romanization_of_Japanese">romaji</a> through an online translator. So, this post will detail what I did to enable native inputs on my laptop. This guide is specifically for <a href="https://i3wm.org/">i3wm</a>, because it does not obey system settings for languages and inputs.</p>
|
||||
|
||||
<h2 id="adding-font-support-to-linux">Adding font support to Linux</h2>
|
||||
<p>Firstly, we need fonts. Depending on your system, these may already be installed. For Japanese, I only used <code class="highlighter-rouge">vlgothic</code>, so here in the package for it:</p>
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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
13270
assets/js/brython.js
Normal file
File diff suppressed because one or more lines are too long
3
assets/js/brython_modules.js
Normal file
3
assets/js/brython_modules.js
Normal file
@ -0,0 +1,3 @@
|
||||
__BRYTHON__.VFS_timestamp = 1567274019809
|
||||
__BRYTHON__.use_VFS = true
|
||||
__BRYTHON__.VFS = {}
|
3
assets/js/brython_stdlib.js
Normal file
3
assets/js/brython_stdlib.js
Normal file
File diff suppressed because one or more lines are too long
156
assets/python/shift2demo.py
Normal file
156
assets/python/shift2demo.py
Normal 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
127
assets/python/shift2mini.py
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user