generated from rochacbruno/python-project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More readme and some endianness testing
- Loading branch information
Showing
5 changed files
with
165 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#! /usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# vim: set et sw=4 fenc=utf-8: | ||
# | ||
# example1.py | ||
|
||
import json | ||
import js2pysecrets | ||
|
||
# // generate a 512-bit key | ||
# key = js2pysecrets.random(512) // => key is a hex string | ||
key = js2pysecrets.random(512) | ||
print(key) | ||
|
||
# // split into 10 shares with a threshold of 5 | ||
# shares = js2pysecrets.share(key, 10, 5) | ||
# // => shares = ['801xxx...xxx','802xxx...xxx','803xxx...xxx','804xxx...xxx','805xxx...xxx'] | ||
shares = js2pysecrets.share(key, 10, 5) | ||
print(shares) | ||
|
||
# // combine 4 shares | ||
# var comb = secrets.combine(shares.slice(0, 4)) | ||
# console.log(comb === key) // => false | ||
# | ||
# // combine 5 shares | ||
# comb = secrets.combine(shares.slice(4, 9)) | ||
# console.log(comb === key) // => true | ||
# | ||
# // combine ALL shares | ||
# comb = secrets.combine(shares) | ||
# console.log(comb === key) // => true | ||
# | ||
# // create another share with id 8 | ||
# var newShare = secrets.newShare(8, shares) // => newShare = '808xxx...xxx' | ||
# | ||
# // reconstruct using 4 original shares and the new share: | ||
# comb = secrets.combine(shares.slice(1, 5).concat(newShare)) | ||
# console.log(comb === key) // => true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#! /usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# vim: set et sw=4 fenc=utf-8: | ||
# | ||
# example1.py | ||
|
||
import json | ||
import js2pysecrets | ||
|
||
# var pw = "<<PassWord123>>" | ||
pw = "<<PassWord123>>" | ||
|
||
# // convert the text into a hex string | ||
# var pwHex = secrets.str2hex(pw) // => hex string | ||
jsHex = js2pysecrets.str2hex(pw) | ||
print(jsHex) | ||
|
||
pyHex = pw.encode('utf-16-be').hex().lstrip('fe') | ||
print(pyHex) | ||
|
||
# // split into 5 shares, with a threshold of 3 | ||
# var shares = secrets.share(pwHex, 5, 3) | ||
# | ||
# // combine 2 shares: | ||
# var comb = secrets.combine(shares.slice(1, 3)) | ||
# | ||
# //convert back to UTF string: | ||
# comb = secrets.hex2str(comb) | ||
# console.log(comb === pw) // => false | ||
# | ||
# // combine 3 shares: | ||
# comb = secrets.combine([shares[1], shares[3], shares[4]]) | ||
# | ||
# //convert back to UTF string: | ||
# comb = secrets.hex2str(comb) | ||
# console.log(comb === pw) // => true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters