11.07.2015 Views

Cryptography - Sage

Cryptography - Sage

Cryptography - Sage

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Python (hence SAGE) has useful datastructures called lists, tuples, and dictionaries whichcan be used to collect objects in SAGE.sage: type([])sage: type(())sage: type({})The list and tuple types collects sequences of data which is indexed like strings:sage: s = [ 16, 9, 4, 1, 0, 1, 4, 9, 16 ]sage: t = ( 16, 9, 4, 1, 0, 1, 4, 9, 16 )sage: [ s[i] == t[i] for i in range(9) ][True, True, True, True, True, True, True, True, True]Note that all strings, lists, and tuples are indexed from 0 and range(n) returns the list ofelements from 0 to 9:sage: range(9)[0, 1, 2, 3, 4, 5, 6, 7, 8]The main distinction is that tuples are immutable:sage: t[0] = 4---------------------------------------------------------------------------Traceback (most recent call last)...: ’tuple’ object does not support item assignmentwhile list elements can be reassigned:sage: s[0] = 4sage: s[8] = 4sage: s[4, 9, 4, 1, 0, 1, 4, 9, 4]92 Appendix A. SAGE Constructions

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!