Browse Source

Added sandyclaws + some game functions

Yay! We got a celeb
master
The Dod 10 years ago
parent
commit
bad74c50d6
  1. 43
      darkened.py
  2. 38
      index.html
  3. 5
      players.csv

43
darkened.py

@ -1,9 +1,14 @@
#!/usr/bin/env python3
import random import random
import time
import codecs import codecs
import json import json
import csv
import textwrap
CHAR_REDACTED = '\u2588' # Full block. CHAR_REDACTED = '\u2588' # Full block.
CHAR_CONFLICT = '\u2573' # Box drawings light diagonal cross. CHAR_CONFLICT = '\u2573' # Box drawings light diagonal cross.
NTRUSTEES = 3 # for now(?)
#------ begin prefab input #------ begin prefab input
cipher1 = [ cipher1 = [
@ -82,6 +87,10 @@ encoded to base64.
You think this random function is weak? *Celebrate* that ;)""" You think this random function is weak? *Celebrate* that ;)"""
return random._urandom(len(b)) 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): def xor2(c1,c2):
return c1^c2 return c1^c2
@ -107,15 +116,15 @@ def _unredact(cipher,pad):
return(CHAR_CONFLICT*len(cipher)) return(CHAR_CONFLICT*len(cipher))
return str(bytes(map(xor2,cipher,pad)),'utf8','replace') return str(bytes(map(xor2,cipher,pad)),'utf8','replace')
def _disintegrate(value,k=8): def _disintegrate(value,k=NTRUSTEES):
lucky = random.randint(0,k-1) lucky = random.randint(0,k-1)
return [i==lucky and value or None for i in range(k)] return [i==lucky and value or None for i in range(k)]
def disintegrate(msg,k=8): def disintegrate(msg,k=NTRUSTEES):
zipped = mapmsgs(lambda p:_disintegrate(p,k),msg) zipped = mapmsgs(lambda p:_disintegrate(p,k),msg)
return [mapmsgs(lambda v:v[i],zipped) for i in range(k)] return [mapmsgs(lambda v:v[i],zipped) for i in range(k)]
def redact(s,k=8): def redact(s,k=NTRUSTEES):
redaction = mapmsgs(_redact,str2msg(s)) redaction = mapmsgs(_redact,str2msg(s))
return { return {
'cipher': msgget(redaction,'cipher'), 'cipher': msgget(redaction,'cipher'),
@ -128,12 +137,34 @@ def unredact(cipher64,*pads64):
mapmsgs(base642bytes, mapmsgs(base642bytes,
mapmsgs(integrate,*pads64)))) mapmsgs(integrate,*pads64))))
## Game functions
def getplayers():
"returns players.csv as a dict"
c=csv.reader(open('players.csv'))
names = next(c)
d = {}
for r in c:
p = dict(zip(names,r))
d[p['player']] = p
return d
def choosetrustees(n=NTRUSTEES, exclude=[], players=None):
if players is None:
players = getplayers()
candidates = list(set(players.keys())-set(exclude))
return random.sample(candidates,n)
def testit(): def testit():
"Todo: turn this into proper unit tests, anyone?" "Todo: turn this into proper unit tests, anyone?"
plaintext = """Here's the first line,
followed by a second one"""
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><html lang="en"><head><title>Testing DarkenedAges library</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><pre>')
print('### Redacting prefab plaintext') 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) redaction = redact(plaintext,2)
for pad in redaction['pads']: for pad in redaction['pads']:
print('\n# pOTP >>>') print('\n# pOTP >>>')

38
index.html

@ -1,17 +1,41 @@
<!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>
### Redacting prefab plaintext ### Players
# Sandy Claws (sandyclaws,@sandyclaws):
From the Magic Tuna Show (ask your kids).
# Rabbi Yoav (broyo,@thedod):
Confession sensor technician (CST) and ChurchApproved Rabbi (CAR)
[technically, a priest] in the Geneva parish. Born 2061 in Kibbutz
Tzofna [burnt down during the 2067 reforms]. Graduated Ofakim Yeshiva
(a ChurchApproved institute) 2085. Level 17 communism indicators
(mainly due to family and origin). 77% heterosexual. No other known
dominant deviatoins.
# Forth Inc. (forth,@forth):
Registered ████████.
# Daan II (daanii,@black_puppydog):
██ ███ ███████ of ██████.
### Simulating a random selection of 3 trustees for msgid #DA14341720253787
['daanii', 'forth', 'broyo']
### Redacting prefab plaintext (2 trustees)
# pOTP >>> # pOTP >>>
[['ElQpAS8v', None, 'u00NLPA=', 'jJgkj/w='], [None, None, 'iA==', None, '9kHo']] [[None, None, None, 'lkwXFnI='], ['RZbLFdmBs6I=', None, 'Yw==', None, '40cX']]
# >>> Unredaction # >>> Unredaction
Here's ███ first line, ██████ ███ █████ line,
████████ ██ a ██████ one followed ██ a ██████ one
# pOTP >>> # pOTP >>>
[[None, '8HvL', None, None], ['kUbc53cUs/s=', 'U/w=', None, 'WtAU4/tV', None]] [['Fa/b2OSk', 'ldGy', 'lofC2bA=', None], [None, 'wIc=', None, 'p4kCjP/a', None]]
# >>> Unredaction # >>> Unredaction
██████ the █████ █████ Here's the first █████
followed by █ second ███ ████████ by █ second ███
### >>> integration >>> ### >>> integration >>>
Here's the first line, Here's the first line,

5
players.csv

@ -1,4 +1,5 @@
player,twister,name,bio player,twister,name,bio
broyo,thedod,Rabbi Yoav,"Confession sensor technician (CST) and ChurchApproved Rabbi (CAR) [technically, a priest] in the Geneva parish. Born 2061 in Kibbutz Tzofna [burnt down during the 2067 reforms]. Graduated Ofakim Yeshiva (a ChurchApproved institute) 2085. Level 17 communism indicators (mainly due to family and origin). 77% heterosexual. No other known dominant deviatoins." broyo,thedod,Rabbi Yoav,"Confession sensor technician (CST) and ChurchApproved Rabbi (CAR) [technically, a priest] in the Geneva parish. Born 2061 in Kibbutz Tzofna [burnt down during the 2067 reforms]. Graduated Ofakim Yeshiva (a ChurchApproved institute) 2085. Level 17 communism indicators (mainly due to family and origin). 77% heterosexual. No other known dominant deviatoins."
forth,forth,Forth Inc.,Registered ████████ forth,forth,Forth Inc.,Registered ████████.
daanii,black_puppydog,Daan II,██ ███ ███████ of ██████ daanii,black_puppydog,Daan II,██ ███ ███████ of ██████.
sandyclaws,sandyclaws,Sandy Claws,From the Magic Tuna Show (ask your kids).

1 player twister name bio
2 broyo thedod Rabbi Yoav Confession sensor technician (CST) and ChurchApproved Rabbi (CAR) [technically, a priest] in the Geneva parish. Born 2061 in Kibbutz Tzofna [burnt down during the 2067 reforms]. Graduated Ofakim Yeshiva (a ChurchApproved institute) 2085. Level 17 communism indicators (mainly due to family and origin). 77% heterosexual. No other known dominant deviatoins.
3 forth forth Forth Inc. Registered ████████ Registered ████████.
4 daanii black_puppydog Daan II ██ ███ ███████ of ██████ ██ ███ ███████ of ██████.
5 sandyclaws sandyclaws Sandy Claws From the Magic Tuna Show (ask your kids).
Loading…
Cancel
Save