Browse Source

Format change (a bit of a rewrite) for easier pastes/twists

master
The Dod 10 years ago
parent
commit
4a6a19db51
  1. 2
      README.md
  2. 169
      darkened.py
  3. 55
      index.html

2
README.md

@ -14,6 +14,8 @@ @@ -14,6 +14,8 @@
#### Slightly longer examples [here](http://bl.ocks.org/thedod/raw/7a4a81224b5bed676b00/) and [here](https://pastee.org/v46af).
For public moves and gossip, see [#DarkenedAges](https://twisterio.com/search?kw=%23darkenedages) on [twister](http://twister.net.co)
### In AD 2101, peace was beginning.
The Unigalitarian Church has abolished the internet. A source of a century of war, misfortune, and mistrust.

169
darkened.py

@ -10,43 +10,6 @@ CHAR_REDACTED = '\u2588' # Full block. @@ -10,43 +10,6 @@ CHAR_REDACTED = '\u2588' # Full block.
CHAR_CONFLICT = '\u2573' # Box drawings light diagonal cross.
NTRUSTEES = 3 # for now(?)
#------ begin prefab input
cipher1 = [
['lgPNUJU8', 'qLvBBQ==', '5GfdMat4', 'z8hPe4BlxxdUMXzi4w==', '2IheMA==',
'uZyB', 'wVCtnQ==', 'VnU=', '/pTNipiB55M=', 'XcT1gQ==', 'gxU8', '9MYX',
'io0='],
['0fOyC2/y', 'bg8=', 'bu2T', 'rJH6dWUzpg==', 'B4BTkvtl', '+Ug=', '6wky',
'H78=', 'nx8=', 'TO3/fbE=', 'tqw=', 'S4k8', '+mXOsQ==', 'E3rblIM=',
'bIu6qbrh1g=='],
['sfjl', 'JBxnLbfe0k0n', 'BShgq+QrmdquMA==', 'VYD1hx8=', 'MLk=', 'ig==',
'oasqOoWF', 'Asw=', 'Rof1s/gpQQONcnk=', 'ZW3zOSnTvyg=', 'QlA=',
'6Q0qOw=='],
['9fPa', '2mFZdDltLL4=', '13vdBg==', '+eWH', 'koB24LLGnxs=', 'CedkJ3k=',
'b41+QUU=', 'fRkV', '4/Yc', 'anY6cA==', 'muk=', '9LrH', '5t1uXU0=',
'M1eqTaWs'],
['8Ah2Pq4=', 'ouQ=', 'miJQVgwle6yOcg==', 'PPc=', '6jes', 'kYsY2ynZdg==']]
pad1 = [
['xWusIv5F', '29q4dg==', 'zAa7Rc4K', 'pqY7HvIXqHA1RRWMhA==', None, None,
'lSXD+g==', None, None, None, None, None, None],
['sJDRbhyB', None, None, None, None, 'uDs=', 'jWhA', None, '6Ho=',
'J4OQCp0=', '39g=', 'JuhF', 'kgS41A==', 'fR+t8fE=', None],
['5ZCA', None, None, None, 'Wco=', None, None, None, 'L+mR1ohML2foHA0=',
None, None, None],
['sbuL', 'qhM8EFAOWM0=', 'oxO8cg==', None, '/eYQidGv/nc=', 'epMLVQA=',
None, None, 'i5dv', 'Dh9fFA==', None, 'gNKi', 'lrEPMyg=', None],
[None, None, '+UoxOmBAFcvrFg==', 'Xo4=', None, '4f56t0C6WA==']]
pad2 = [
[None, None, None, None, 'nvo/RQ==', '7ebk', None, 'Pxs=',
'jvG/+ffvzr8=', 'KayU9Q==', '8H1Z', 'nKdz', '5OI='],
[None, 'GmA=', 'GoX2', '/OSQHAtXxw==', 'd+Ej94lL', None, None, 'fsw=',
None, None, None, None, None, None, 'AO7bwt+F+A=='],
[None, 'YXBKZdaztixJ', 'YEYD2Z1b7bPBXg==', 'NvKU5HQ=', None, '6w==',
'085ZT+nx', 'bao=', None, 'FwiAXEih3EA=', 'ICk=', 'r1l+FQ=='],
[None, None, None, 'jY3i', None, None, 'R/kWIDE=', 'O01B', None, None,
'84c=', None, 'kq8PNCM=', 'UCXLPs2F'],
['h2cYGdo=', 'wIE=', None, None, 'nl/J', None]]
#------ end prefab input
## [['an', 'msg', 'is', 'a', 'list', 'of', 'lines,'],
## ['where', 'each', 'line', 'is', 'a', 'list', 'of', 'words.']]
def str2msg(s):
@ -87,10 +50,6 @@ encoded to base64. @@ -87,10 +50,6 @@ encoded to base64.
You think this random function is weak? *Celebrate* that ;)"""
return random._urandom(len(b))
def makeid():
"Looks fancy enough and would probably never collide"
return 'DA{:.4f}'.format(time.time()).replace('.','')
def xor2(c1, c2):
return c1^c2
@ -124,13 +83,29 @@ def disintegrate(msg,k=NTRUSTEES): @@ -124,13 +83,29 @@ def disintegrate(msg,k=NTRUSTEES):
zipped = mapmsgs(lambda p:_disintegrate(p, k), msg)
return [mapmsgs(lambda v:v[i], zipped) for i in range(k)]
def redact(s,k=NTRUSTEES):
redaction = mapmsgs(_redact,str2msg(s))
return {
'cipher': msgget(redaction,'cipher'),
'pads': disintegrate(msgget(redaction,'pad'),k)}
def redact(s, sender, recipients=[], subject="(untitled)", k=NTRUSTEES):
msgid = makeid()
trustees = choosetrustees(k,exclude=[sender]+recipients)
header = {
"msgid": msgid, "sender": sender, "recipients": recipients,
"subject": subject, "trustees": trustees}
def unredact(cipher64,*pads64):
redaction = mapmsgs(_redact, str2msg(s))
pads = dict(zip(trustees,disintegrate(msgget(redaction, 'pad'), len(trustees))))
result = {}
result['__public__'] = header.copy()
result['__public__']['cipher'] = msgget(redaction, 'cipher')
result['__to__'] = header.copy()
result['__to__']['pads'] = pads # the whole shebang
for t in trustees:
result[t] = header.copy()
result[t]['pads'] = {t: pads[t]}
return result;
def unredact(cipher, pads, trustees=[]):
cipher64 = cipher['cipher']
pads64 = [pads['pads'][t] for t in pads['pads']
if not trustees or t in trustees]
return msg2str(mapmsgs(
_unredact,
mapmsgs(base642bytes, cipher64),
@ -138,6 +113,13 @@ def unredact(cipher64,*pads64): @@ -138,6 +113,13 @@ def unredact(cipher64,*pads64):
mapmsgs(integrate, *pads64))))
## Game functions
def makeid():
"""msgid (e.g. can be used as hashtags in move twists).
Sorting by it is like sorting by time,
it looks fancy enough, and would probably never collide"""
return 'DA{:.4f}'.format(time.time()).replace('.', '')
def getplayers():
"returns players.csv as a dict"
c=csv.reader(open('players.csv'))
@ -148,40 +130,93 @@ def getplayers(): @@ -148,40 +130,93 @@ def getplayers():
d[p['player']] = p
return d
def choosetrustees(n=NTRUSTEES, exclude=[], players=None):
def choosetrustees(k=NTRUSTEES, exclude=[], players=None):
if players is None:
players = getplayers()
candidates = list(set(players.keys())-set(exclude))
return random.sample(candidates,n)
return random.sample(candidates, k)
#------ begin prefab redaction
prefab = {
"__public__": {"trustees": ["ted", "dan"], "sender": "alice",
"msgid": "DA14341968415407", "recipients": ["bob", "carol"],
"subject": "Hey, sport. YOU connect the dots.", "cipher":
[["lgPNUJU8", "qLvBBQ==", "5GfdMat4", "z8hPe4BlxxdUMXzi4w==",
"2IheMA==", "uZyB", "wVCtnQ==", "VnU=", "/pTNipiB55M=", "XcT1gQ==",
"gxU8", "9MYX", "io0="], ["0fOyC2/y", "bg8=", "bu2T", "rJH6dWUzpg==",
"B4BTkvtl", "+Ug=", "6wky", "H78=", "nx8=", "TO3/fbE=", "tqw=",
"S4k8", "+mXOsQ==", "E3rblIM=", "bIu6qbrh1g=="], ["sfjl",
"JBxnLbfe0k0n", "BShgq+QrmdquMA==", "VYD1hx8=", "MLk=", "ig==",
"oasqOoWF", "Asw=", "Rof1s/gpQQONcnk=", "ZW3zOSnTvyg=", "QlA=",
"6Q0qOw=="], ["9fPa", "2mFZdDltLL4=", "13vdBg==", "+eWH",
"koB24LLGnxs=", "CedkJ3k=", "b41+QUU=", "fRkV", "4/Yc", "anY6cA==",
"muk=", "9LrH", "5t1uXU0=", "M1eqTaWs"], ["8Ah2Pq4=", "ouQ=",
"miJQVgwle6yOcg==", "PPc=", "6jes", "kYsY2ynZdg=="]]}, "dan":
{"trustees": ["ted", "dan"], "sender": "alice", "msgid":
"DA14341968415407", "pads": {"dan": [[None, None, None, None,
"nvo/RQ==", "7ebk", None, "Pxs=", "jvG/+ffvzr8=", "KayU9Q==", "8H1Z",
"nKdz", "5OI="], [None, "GmA=", "GoX2", "/OSQHAtXxw==", "d+Ej94lL",
None, None, "fsw=", None, None, None, None, None, None,
"AO7bwt+F+A=="], [None, "YXBKZdaztixJ", "YEYD2Z1b7bPBXg==",
"NvKU5HQ=", None, "6w==", "085ZT+nx", "bao=", None, "FwiAXEih3EA=",
"ICk=", "r1l+FQ=="], [None, None, None, "jY3i", None, None,
"R/kWIDE=", "O01B", None, None, "84c=", None, "kq8PNCM=", "UCXLPs2F"],
["h2cYGdo=", "wIE=", None, None, "nl/J", None]]}, "recipients":
["bob", "carol"], "subject": "Hey, sport. YOU connect the dots."},
"__to__": {"trustees": ["ted", "dan"], "sender": "alice", "msgid":
"DA14341968415407", "pads": {"dan": [[None, None, None, None,
"nvo/RQ==", "7ebk", None, "Pxs=", "jvG/+ffvzr8=", "KayU9Q==", "8H1Z",
"nKdz", "5OI="], [None, "GmA=", "GoX2", "/OSQHAtXxw==", "d+Ej94lL",
None, None, "fsw=", None, None, None, None, None, None,
"AO7bwt+F+A=="], [None, "YXBKZdaztixJ", "YEYD2Z1b7bPBXg==",
"NvKU5HQ=", None, "6w==", "085ZT+nx", "bao=", None, "FwiAXEih3EA=",
"ICk=", "r1l+FQ=="], [None, None, None, "jY3i", None, None,
"R/kWIDE=", "O01B", None, None, "84c=", None, "kq8PNCM=", "UCXLPs2F"],
["h2cYGdo=", "wIE=", None, None, "nl/J", None]], "ted": [["xWusIv5F",
"29q4dg==", "zAa7Rc4K", "pqY7HvIXqHA1RRWMhA==", None, None,
"lSXD+g==", None, None, None, None, None, None], ["sJDRbhyB", None,
None, None, None, "uDs=", "jWhA", None, "6Ho=", "J4OQCp0=", "39g=",
"JuhF", "kgS41A==", "fR+t8fE=", None], ["5ZCA", None, None, None,
"Wco=", None, None, None, "L+mR1ohML2foHA0=", None, None, None],
["sbuL", "qhM8EFAOWM0=", "oxO8cg==", None, "/eYQidGv/nc=", "epMLVQA=",
None, None, "i5dv", "Dh9fFA==", None, "gNKi", "lrEPMyg=", None],
[None, None, "+UoxOmBAFcvrFg==", "Xo4=", None, "4f56t0C6WA=="]]},
"recipients": ["bob", "carol"], "subject": "Hey, sport. YOU connect"
"the dots."}, "ted": {"trustees": ["ted", "dan"], "sender": "alice",
"msgid": "DA14341968415407", "pads": {"ted": [["xWusIv5F", "29q4dg==",
"zAa7Rc4K", "pqY7HvIXqHA1RRWMhA==", None, None, "lSXD+g==", None,
None, None, None, None, None], ["sJDRbhyB", None, None, None, None,
"uDs=", "jWhA", None, "6Ho=", "J4OQCp0=", "39g=", "JuhF", "kgS41A==",
"fR+t8fE=", None], ["5ZCA", None, None, None, "Wco=", None, None,
None, "L+mR1ohML2foHA0=", None, None, None], ["sbuL", "qhM8EFAOWM0=",
"oxO8cg==", None, "/eYQidGv/nc=", "epMLVQA=", None, None, "i5dv",
"Dh9fFA==", None, "gNKi", "lrEPMyg=", None], [None, None,
"+UoxOmBAFcvrFg==", "Xo4=", None, "4f56t0C6WA=="]]}, "recipients":
["bob", "carol"], "subject": "Hey, sport. YOU connect the dots."}}
#------ end prefab redaction
def testit():
"Todo: turn this into proper unit tests, anyone?"
print('<!DOCTYPE html><html lang="en"><head><title>Testing DarkenedAges library</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><pre>')
print('<!DOCTYPE html>\n<html lang="en"><head><title>Testing DarkenedAges library</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><pre>')
print('### Players')
for p in getplayers().values():
print('\n# {name} ({player}, @{twister}):'.format(**p))
print('\n'.join(' '+l for l in textwrap.wrap(p['bio'])))
print('\n\n### Simulating a random selection of {} trustees for msgid #{}'.format(NTRUSTEES,makeid()))
print(choosetrustees(exclude=['GCHQ'])) # Wishful thinking ;)
print('\n\n### Redacting prefab plaintext (2 trustees)')
plaintext = "Here's the first line, \nfollowed by a second one"
redaction = redact(plaintext,2)
for pad in redaction['pads']:
print('\n# pOTP >>>')
print(pad)
print('# >>> Unredaction')
print(unredact(redaction['cipher'],pad))
redaction = redact(plaintext, 'alice', recipients=['bob','carol'], subject='Is this thing on?', k=2)
for line in textwrap.wrap(json.dumps(redaction)): print(line)
for t in redaction['__public__']['trustees']:
print('\n# >>> Unredaction for trustee: {}'.format(t))
print(unredact(redaction['__public__'], redaction[t]))
print('\n### >>> integration >>>')
print(unredact(redaction['cipher'],*redaction['pads']))
print('\n\n### Simulating incoming [prefab] ciphertext and conflicting pads')
for pad in [pad1,pad2]:
print('\n# pOTP >>>')
#print(json.dumps(pad,indent=4))
print(pad)
print('# >>> Unredaction')
print(unredact(cipher1,pad))
print(unredact(redaction['__public__'], redaction['__to__']))
print('\n\n### Unredaction of prefab message (with conflicting pads)')
for t in prefab['__public__']['trustees']:
print('\n# >>> Unredaction for trustee: {}'.format(t))
print(unredact(prefab['__public__'], prefab[t]))
print('\n### >>> integration >>>')
print(unredact(cipher1,pad1,pad2))
print(unredact(prefab['__public__'], prefab['__to__']))
print('</pre></body></html>')

55
index.html

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
<!DOCTYPE html><html lang="en"><head><title>Testing DarkenedAges library</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><pre>
<!DOCTYPE html>
<html lang="en"><head><title>Testing DarkenedAges library</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><pre>
### Players
# Sandy Claws (sandyclaws, @sandyclaws):
@ -19,43 +20,49 @@ @@ -19,43 +20,49 @@
██ ███ ███████ of ██████.
### Simulating a random selection of 3 trustees for msgid #DA14341720253787
['daanii', 'forth', 'broyo']
### Redacting prefab plaintext (2 trustees)
# pOTP >>>
[[None, None, None, 'lkwXFnI='], ['RZbLFdmBs6I=', None, 'Yw==', None, '40cX']]
# >>> Unredaction
██████ ███ █████ line,
followed ██ a ██████ one
# pOTP >>>
[['Fa/b2OSk', 'ldGy', 'lofC2bA=', None], [None, 'wIc=', None, 'p4kCjP/a', None]]
# >>> Unredaction
Here's the first █████
████████ by █ second ███
{"daanii": {"pads": {"daanii": [["krEZr3A9", null, "Ew+m5z8=",
"zMwQeJk="], [null, "oDo=", "Gg==", null, "LSr3"]]}, "subject": "Is
this thing on?", "sender": "alice", "trustees": ["daanii", "broyo"],
"msgid": "DA14341999781041", "recipients": ["bob", "carol"]},
"__public__": {"cipher": [["2tRryldO", "5F+i", "dWbUlEs=",
"oKV+HbU="], ["to5RIGi8VsQ=", "wkM=", "ew==", "mIQCOq/5", "QkSS"]],
"subject": "Is this thing on?", "sender": "alice", "trustees":
["daanii", "broyo"], "msgid": "DA14341999781041", "recipients":
["bob", "carol"]}, "__to__": {"pads": {"daanii": [["krEZr3A9", null,
"Ew+m5z8=", "zMwQeJk="], [null, "oDo=", "Gg==", null, "LSr3"]],
"broyo": [[null, "kDfH", null, null], ["0OE9TAfLM6A=", null, null,
"6+FhVcGd", null]]}, "subject": "Is this thing on?", "sender":
"alice", "trustees": ["daanii", "broyo"], "msgid": "DA14341999781041",
"recipients": ["bob", "carol"]}, "broyo": {"pads": {"broyo": [[null,
"kDfH", null, null], ["0OE9TAfLM6A=", null, null, "6+FhVcGd", null]]},
"subject": "Is this thing on?", "sender": "alice", "trustees":
["daanii", "broyo"], "msgid": "DA14341999781041", "recipients":
["bob", "carol"]}}
# >>> Unredaction for trustee: daanii
Here's ███ first line,
████████ by a ██████ one
# >>> Unredaction for trustee: broyo
██████ the █████ █████
followed ██ █ second ███
### >>> integration >>>
Here's the first line,
followed by a second one
### Simulating incoming [prefab] ciphertext and conflicting pads
### Unredaction of prefab message (with conflicting pads)
# pOTP >>>
[['xWusIv5F', '29q4dg==', 'zAa7Rc4K', 'pqY7HvIXqHA1RRWMhA==', None, None, 'lSXD+g==', None, None, None, None, None, None], ['sJDRbhyB', None, None, None, None, 'uDs=', 'jWhA', None, '6Ho=', 'J4OQCp0=', '39g=', 'JuhF', 'kgS41A==', 'fR+t8fE=', None], ['5ZCA', None, None, None, 'Wco=', None, None, None, 'L+mR1ohML2foHA0=', None, None, None], ['sbuL', 'qhM8EFAOWM0=', 'oxO8cg==', None, '/eYQidGv/nc=', 'epMLVQA=', None, None, 'i5dv', 'Dh9fFA==', None, 'gNKi', 'lrEPMyg=', None], [None, None, '+UoxOmBAFcvrFg==', 'Xo4=', None, '4f56t0C6WA==']]
# >>> Unredaction
# >>> Unredaction for trustee: ted
Sharky says (after interrogating ████ ███ Tung ██ ████████ ████ ███ ███ ██
access ██ ███ ███████ ██████ As far ██ we know, it may have never ███████
The █████████ ██████████ █████ is █ ██████ ██ independent ████████ ██ ████
DHQ predicts that ███ official story █████ ███ has died ██ the plane ██████
█████ ██ challenged by ███ public.
# pOTP >>>
[[None, None, None, None, 'nvo/RQ==', '7ebk', None, 'Pxs=', 'jvG/+ffvzr8=', 'KayU9Q==', '8H1Z', 'nKdz', '5OI='], [None, 'GmA=', 'GoX2', '/OSQHAtXxw==', 'd+Ej94lL', None, None, 'fsw=', None, None, None, None, None, None, 'AO7bwt+F+A=='], [None, 'YXBKZdaztixJ', 'YEYD2Z1b7bPBXg==', 'NvKU5HQ=', None, '6w==', '085ZT+nx', 'bao=', None, 'FwiAXEih3EA=', 'ICk=', 'r1l+FQ=='], [None, None, None, 'jY3i', None, None, 'R/kWIDE=', 'O01B', None, None, '84c=', None, 'kq8PNCM=', 'UCXLPs2F'], ['h2cYGdo=', 'wIE=', None, None, 'nl/J', None]]
# >>> Unredaction
# >>> Unredaction for trustee: dan
██████ ████ ██████ █████████████ Frau Tze ████ in person), that she had no
██████ to the Pujinda paper. ██ ███ as ██ █████ ██ ███ ████ █████ leaked.
███ El-Hamdan encryption crack ██ a result of ███████████ research by FTT.

Loading…
Cancel
Save