py3rijndael | Rijndael algorithm library for Python3 | Learning library
kandi X-RAY | py3rijndael Summary
kandi X-RAY | py3rijndael Summary
Rijndael algorithm library for Python3
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Multiply two bits
- Multiply a and b
- Multiply two values
py3rijndael Key Features
py3rijndael Examples and Code Snippets
Community Discussions
Trending Discussions on py3rijndael
QUESTION
import unittest
import base64
from py3rijndael import Rijndael
import os
import codecs
#plain text
a=input("Please Enter Plain text: ")
plain_text = a.encode('utf-8')
padded_text = plain_text.ljust(32, b'\x1b')
#key
key=input()
key_bytes = codecs.encode(key, 'UTF-8')
#key_bytes = key.encode('utf-8') #two change string to byte
#base64_key_bytes = base64.b64encode(key_bytes) #base 64 encryption
key_bytes = key_bytes[2:-1]
print(key_bytes)
#encryption
rijndael_key = Rijndael(key_bytes, block_size=32)
cipher = rijndael_key.encrypt(padded_text)
print(cipher)
...ANSWER
Answered 2021-Jan-19 at 12:26Guess you are using python3. (It's totally different on python2 and python3.)
Firstly, let's try to explain why it happens.
You copy a b"\x08\xda...
from else where and paste it to prompt. input
will return an str object (unicode of python2), whose first char is 'b', second is '"', third is '\', forth is 'x', etc.
When it encodes, it becomes a byte string with same characters(represented in bytes), as there are only ascii chars.
Then there is print. What is a byte '\'
be printed? It's printed as b'\\'
that's why you see double back slashes.
An easy (but dangerous) way.
After reading from prompt, eval
it. That is, execute it just like python codes. And then you will get what it was when it was first generated by random. In fact input
in python2 did this for you.
But this is of course insecure because the input your users give may contain any possible string and it may contains some malicious snippet.
A better way I can think of.
As a key is always byte string, and byte strings are generally unprintable. So you need to transform it to something printable, copy-and-paste it here, and de-transform it back. maybe base64 encoding may help you do this.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install py3rijndael
You can use py3rijndael like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page