Opened 12 years ago

Closed 12 years ago

#1840 closed enhancement (fixed)

[with bundle, positive review] Hill cipher addition to crypto package

Reported by: kohel Owned by: cwitty
Priority: minor Milestone: sage-2.10.1
Component: misc Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by malb)

This adds functionality for Hill ciphers as in the following example:

sage: S = AlphabeticStrings()
sage: E = HillCryptosystem(S,7)
sage: E.random_key()

[13  1 23  4 14 15  0]
[11  4  4 12  0 23 14]
[18  4 25 13 10  7 10]
[ 9 14 13 11  1 12 10]
[13  8 10 19 24 13 24]
[ 8  7 12 12 25  2 10]
[ 2  7  1 10 13 12  5]
sage: e = E(E.random_key())
sage: e

[ 1  9  8 17 16  2 13]
[11 12 12 24 12 25  2]
[18 21 20  2 16  7 17]
[17 17  8 19 14 23 19]
[15 11 24  6  5  7  4]
[17 20 18  6 16 13 13]
[ 2 12 17  4 23  4  4]
sage: pt = S([ randint(0,25) for i in range(7*16) ])
sage: pt
QWTWCUQMBMTGDSGTHNJLBNDEXYWGJKHZGAPRFKMPGJDXDLYYGZVTXHLJIMOGKERMWCMOOJKHGCTXAOVIJCXBIGRSLVCBZAXJBCDAEHUZUGCEYCLA
sage: e(pt)
YBQWKZZLXQLKVACTPHEFPHAWYSSUKFVQJGJVGVNYWXDRYMYHXZIBOGJISSTQTOQYQPYNKIVPAQZNJDXJRNPKQUWYRRGRLGERSLXUAWAMXXGSQETD
sage: c = e.inverse()
sage: c(e(pt)) == pt
True
sage: e.key()

[ 1  9  8 17 16  2 13]
[11 12 12 24 12 25  2]
[18 21 20  2 16  7 17]
[17 17  8 19 14 23 19]
[15 11 24  6  5  7  4]
[17 20 18  6 16 13 13]
[ 2 12 17  4 23  4  4]
sage: type(e.key())
<type 'sage.matrix.matrix_modn_dense.Matrix_modn_dense'>
sage: type(e)
<class 'sage.crypto.classical_cipher.HillCipher'>
sage: A = e.key()
sage: A.det()
17

Attachments (2)

crypto_2008.01.18-1.hg (4.5 KB) - added by kohel 12 years ago.
1840-repr.patch (1.8 KB) - added by mhansen 12 years ago.

Download all attachments as: .zip

Change History (7)

Changed 12 years ago by kohel

comment:1 Changed 12 years ago by mhansen

  • Summary changed from Hill cipher addition to crypto package to [with bundle, needs review] Hill cipher addition to crypto package

comment:2 Changed 12 years ago by malb

  • Description modified (diff)

comment:3 Changed 12 years ago by malb

  • Summary changed from [with bundle, needs review] Hill cipher addition to crypto package to [with bundle, mostly positive review] Hill cipher addition to crypto package

Patch looks good and applies cleanly against 2.10. Only detail: It uses __repr__ rather than _repr_ (two instead of one underscore) but inherits from SageObject. All objects inheriting from SageObject are supposed to implement _repr_.

Changed 12 years ago by mhansen

comment:4 Changed 12 years ago by mhansen

  • Summary changed from [with bundle, mostly positive review] Hill cipher addition to crypto package to [with bundle, positive review] Hill cipher addition to crypto package

Works for me, and I posted a second patch changing repr's to _repr_.

comment:5 Changed 12 years ago by mabshoff

  • Resolution set to fixed
  • Status changed from new to closed

Merged in Sage 2.10.1.alpha1

Note: See TracTickets for help on using tickets.