No, that’s not a “
real one-time pad”.
As I explained in another answer of mine…
Per definition, OTP requires the “key“ to be…
- a truly random one-time pad value,
- generated and exchanged in a secure way.
- at least as long as the message, and
- only to be used once.
At the very least, your idea fails the definition in points 1 (calculated checksum != truly random) and 3 (SHA512 has a fixed length, which is bound to differ from the plaintext message length).
Besides that, I hate to disappoint you – but the idea isn’t very new either. Cryptographically secure hashes represent nice cryptographic primitives which are inviting to build upon. Yet, such hashes are also build to be rather “slow”, which raises the question why one would decide to risk security pitfalls and accept slower performance when faster, well-vetted stream and block ciphers are available (most prominent example: AES).
Nevertheless, you might be interested to check up on some related Q&As as the answers to each of these questions hold information which might help you understand things a bit better:
Last but not least, to answer your “
how safe this could be?” – it could be much more secure than what you’re doing right now. Looking at your code it’s obvious you simply hash $k|m$.
pswhash = sha512((psw+str(x)).encode('utf-8')).hexdigest()
Bluntly combining and hashing both key and message is about as bad as it sounds: don’t do it! There are several issues with that approach which might not seem obvious at first sight, but those issues can and will break your neck if you let them. Instead of writing a multi-page essay about that, I’ld rather like to advise you to use a HMAC based on SHA512 (at the very least) since HMACs are made to hash things using a password. You can use HMAC to create a KDF out of SHA512 quick and easy.
Even better would be using a dedicated Key Derivation Function. Or course, a HMAC-based Extract-and-Expand Key Derivation Function (HKDF) is simple and easy to implement… but honestly – from a security point of view – I would recommend using something more dedicated like PBKDF2 (Password-Based Key Derivation Function 2). Combine that with one of the faster, well-vetted ciphers like AES and the information you plan to encrypt has a good chance to be more secure than you could wish for.