From 841f091d1ca63a97f0d53da2046f41184b4f4861 Mon Sep 17 00:00:00 2001 From: artemuhi Date: Sat, 23 Mar 2024 14:07:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20py/converter.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/converter.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/py/converter.py b/py/converter.py index ce3641d..65c8d16 100644 --- a/py/converter.py +++ b/py/converter.py @@ -23,4 +23,40 @@ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -""" \ No newline at end of file +""" +import json +from ecdsa import SigningKey, VerifyingKey, SECP256k1 +from ecdsa.util import PRNG + +f = open('text.txt', 'r') +request = json.load(f) +f.close() + +def p2h(data, keymode): + if(keymode=="sk"): + sk = SigningKey.from_pem(data, curve=SECP256k1) + print(sk.to_string().hex()) + elif(keymode=="vk"): + vk = VerifyingKey.from_pem(data, curve=SECP256k1) + print(vk.to_string().hex()) + +def h2p(data, keymode): + if(keymode=="sk"): + sk = SigningKey.from_string(b16decode(data), curve=SECP256k1) + print(sk.to_pem()) + elif(keymode=="vk"): + vk = VerifyingKey.from_string(b16decode(data), curve=SECP256k1) + print(vk.to_pem()) + +def seed2hkey(data, keymode): + seed = PRNG(data.encode()) + sk = SigningKey.generate(entropy=seed, curve=SECP256k1) + print(sk.to_string().hex()) + +switch = { + "p2h":p2h, + "h2p":h2p, + "seed2hkey":seed2hkey +} + +switch[request["mode"]](request["data"], request("keymode"))