aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md29
-rw-r--r--lc4.py8
2 files changed, 20 insertions, 17 deletions
diff --git a/README.md b/README.md
index 1568b5f..9487cfb 100644
--- a/README.md
+++ b/README.md
@@ -206,16 +206,17 @@ cards could be more innocuous and easily explainable to the secret police than
a set of peculiar numbered tiles.
```
-0 a b c d e f
-g h i j k l m
-n o p q r s t
-u v w x y z _
-. , - + * / :
-? ! ' ( ) 1 2
-3 4 5 6 7 8 9
+a b c d e f g
+h i j k l m n
+o p q r s t u
+v w x y z _ .
+, - + * / : ?
+! ' ( ) 1 2 3
+4 5 6 7 8 9 0
```
-With this layout, the following mapping to playing cards is used:
+**This board uses a 1-based index**, so `a=1`, `b=2`, and so on. With this layout,
+the following mapping to playing cards is used:
| **Character** | Card | Index | **Character** | Card | Index | **Character** | Card | Index | **Character** | Card | Index |
|-----------|------|-------|-----------|------|-------|-----------|------|-------|-----------|------|--------|
@@ -242,12 +243,12 @@ Heart is left as an exercise for the reader.
For LC4, the following board could be used:
```
-# a b c d e
-f g h i j k
-l m n o p q
-r s t u v w
-x y z _ 2 3
-4 5 6 7 8 9
+a b c d e f
+g h i j k l
+m n o p q r
+s t u v w x
+y z _ 2 3 4
+5 6 7 8 9 #
```
The "Hearts" suit would be ommitted from the card mapping table, and the index
diff --git a/lc4.py b/lc4.py
index 5a2785f..fea2f7a 100644
--- a/lc4.py
+++ b/lc4.py
@@ -151,9 +151,11 @@ def rotate_marker_down(m, col, n):
return ((m[0] + n) % size, m[1])
-def derive_key(password):
+def derive_key(password, one_indexed):
i = 0
k = letters
+ # if using one-indexed arrays, moves the zero element to the end
+ if one_indexed: k = k[1:]+k[0]
for c in password:
(row, col) = find_ix(c)
k = rotate_down(rotate_right(k, i, col), i, row)
@@ -295,7 +297,7 @@ def test1(size, fixednonce):
else:
keyword = 's3cret_p4ssw0rd/31337'
szkeyword = keyword # This statement needed to show keyword in printinfo() [don't change args.keywordstring within test1()!]
- key = derive_key(keyword)
+ key = derive_key(keyword, false)
else:
key = letters
initialkey = key
@@ -433,7 +435,7 @@ if __name__ == '__main__':
if args.keywordfile: args.keywordstring = open(args.keywordfile, 'r').read().rstrip('\r\n')
if args.keywordstring:
szkeyword = args.keywordstring
- key = derive_key(args.keywordstring)
+ key = derive_key(args.keywordstring, args.playingcard)
if args.keyfile: args.keystring = open(args.keyfile, 'r').read().rstrip('\r\n')
if args.keystring: key = args.keystring;