Python Forum
Hash command works differently for me in CMD and Spyder
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hash command works differently for me in CMD and Spyder
#1
I have a problem, my code uses the hash command to "encrypt" a number, the problem is that when I run the process through the Spyder program it gives me an X number and when I run the same code from CMD I get a completely different one. Why? Huh Huh


This is my function that encrypt my number.

import ctypes

def encriptar(number, seed):
    codigo = (number, seed)
    hash_number = ctypes.c_size_t(hash(codigo)).value
    return 'R' + str(hash_number)

number = encriptar(123456789, 123456)
print(number)
For Spyder the resulting number is 5923383283137266694
For CMD the resulting number is 1809990662

It should be noted that the version of python in Spyder is 3.7.3 and the version installed in the system is 3.7.2

Any information that I have missed to mention please tell me.

Thanks...
Reply
#2
The hash() may return different values for the same object on different Python implementations and Python versions.
It is designed to be used only within a single Python session. So you should never rely on the value of hash() beyond this.
If you need hashing that yields the same results everywhere, use hashlib or xxhash instead.
Reply
#3
I thought that by using a seed you could have some control over the hash(), I will start using the modules you recommended, thanks.
Reply
#4
In the same version, yes. It's used for unittests.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] How to crack hash with hashlib Milan 0 1,403 Mar-09-2023, 08:25 PM
Last Post: Milan
  List comprehension used differently coder_sw99 3 1,710 Oct-03-2021, 04:12 PM
Last Post: coder_sw99
  Two loops behaving differently DavidTheGrockle 5 2,525 Dec-27-2020, 03:56 AM
Last Post: deanhystad
  Script works when executed from command prompt but not when executed in SDP Tippex 0 2,000 Apr-07-2020, 04:26 PM
Last Post: Tippex
  code works at command line but not in .py ridgerunnersjw 4 2,555 Sep-12-2019, 11:09 PM
Last Post: ridgerunnersjw
  length constraint on phrase hash to password javaben 0 1,907 Aug-21-2019, 05:34 PM
Last Post: javaben
  Create file archive that contains crypto hash ED209 1 2,046 May-29-2019, 03:05 AM
Last Post: heiner55
  Fastest dict/map method when 'key' is already a hash? tasket 6 3,982 Apr-20-2019, 06:40 PM
Last Post: tasket
  Cant run command python in PyCharm, but it works in cmd LevG0r 1 2,805 Sep-09-2018, 06:21 PM
Last Post: Axel_Erfurt
  hash v2 and v3 help Normalitie 7 4,327 Mar-22-2018, 01:57 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020