summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLegrandin <helderijs@gmail.com>2013-12-17 22:05:57 +0100
committerDwayne Litzenberger <dlitz@dlitz.net>2014-02-21 23:59:53 -0800
commit74efe78ac1c82fb09d4d390093d4c9597167d3ec (patch)
treed420cc0f80209c0c13470f96ff6a46a38b226581
parentb08530a098a045e949fae6ec87cb9a5e25d446b3 (diff)
downloadpycrypto-74efe78ac1c82fb09d4d390093d4c9597167d3ec.tar.gz
Better example (with nonce) for Counter object
-rw-r--r--lib/Crypto/Util/Counter.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/Crypto/Util/Counter.py b/lib/Crypto/Util/Counter.py
index 5a6fd77..eeff93c 100644
--- a/lib/Crypto/Util/Counter.py
+++ b/lib/Crypto/Util/Counter.py
@@ -43,12 +43,14 @@ An example of usage is the following:
>>> from Crypto.Cipher import AES
>>> from Crypto.Util import Counter
+ >>> from Crypto import Random
>>>
- >>> pt = b'X'*1000000
- >>> ctr = Counter.new(128)
+ >>> nonce = Random.get_random_bytes(8)
+ >>> ctr = Counter.new(64, nonce)
>>> key = b'AES-128 symm key'
+ >>> plaintext = b'X'*1000000
>>> cipher = AES.new(key, AES.MODE_CTR, counter=ctr)
- >>> ct = cipher.encrypt(pt)
+ >>> ciphertext = cipher.encrypt(plaintext)
:undocumented: __package__
"""
@@ -70,7 +72,7 @@ def new(nbits, prefix=b(""), suffix=b(""), initial_value=1, overflow=0, little_e
Each call to the function returns the next counter block.
Each counter block is made up by three parts::
-
+
prefix || counter value || postfix
The counter value is incremented by 1 at each call.