How to fix python int too large to convert to c long
Im using windows 10 to generate a security code for my DVR that i forgot the password.
Installed Python 3.7.2 on my Notebook
RAM:16GB
HDD:1TB
#!/usr/bin/env python3
import sys
from re import search
from numpy import uint32
from requests import get
from datetime import datetime
def keygen(seed):
magic = 0
for i, char in enumerate(seed):
i += 1
magic += i * ord(char) ^ i
secret = str(uint32(1751873395 * magic))
c = str.maketrans("012345678", "QRSqrdeyz")
return secret.translate(c)
def get_serial_date(ip):
try:
req = get("http://192.168.178.43/upnpdevicedesc.xml")
except Exception as e:
print("Unable to connect to {ip}:n{e}")
sys.exit(-1)
model = search("<modelNumber>(.*)</modelNumber>", req.text).group(1)
serial = search("<serialNumber>(.*)</serialNumber>", req.text).group(1)
serial = serial.replace(model, "")
datef = datetime.strptime(req.headers["Date"], "%a, %d %b %Y %H:%M:%S GMT")
date = datef.strftime("%Y%m%d")
return "{serial}{date}"
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: {sys.argv[0]} <ip>")
print("Connects to a device and generates a security key")
sys.exit(1)
seed = get_serial_date(sys.argv[1])
print("Got seed: {seed}")
key = keygen(seed)
print("Generated security key: {key}")
is there a way to fix this error code or i need to do something with my Notebook Settins?
Here is the error code that i get
Got seed: {seed}
Traceback (most recent call last):
File "beer.py", line 41, in <module>
key = keygen(seed)
File "beer.py", line 14, in keygen
secret = str(uint32(1751873395 * magic))
OverflowError: Python int too large to convert to C long
python
add a comment |
Im using windows 10 to generate a security code for my DVR that i forgot the password.
Installed Python 3.7.2 on my Notebook
RAM:16GB
HDD:1TB
#!/usr/bin/env python3
import sys
from re import search
from numpy import uint32
from requests import get
from datetime import datetime
def keygen(seed):
magic = 0
for i, char in enumerate(seed):
i += 1
magic += i * ord(char) ^ i
secret = str(uint32(1751873395 * magic))
c = str.maketrans("012345678", "QRSqrdeyz")
return secret.translate(c)
def get_serial_date(ip):
try:
req = get("http://192.168.178.43/upnpdevicedesc.xml")
except Exception as e:
print("Unable to connect to {ip}:n{e}")
sys.exit(-1)
model = search("<modelNumber>(.*)</modelNumber>", req.text).group(1)
serial = search("<serialNumber>(.*)</serialNumber>", req.text).group(1)
serial = serial.replace(model, "")
datef = datetime.strptime(req.headers["Date"], "%a, %d %b %Y %H:%M:%S GMT")
date = datef.strftime("%Y%m%d")
return "{serial}{date}"
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: {sys.argv[0]} <ip>")
print("Connects to a device and generates a security key")
sys.exit(1)
seed = get_serial_date(sys.argv[1])
print("Got seed: {seed}")
key = keygen(seed)
print("Generated security key: {key}")
is there a way to fix this error code or i need to do something with my Notebook Settins?
Here is the error code that i get
Got seed: {seed}
Traceback (most recent call last):
File "beer.py", line 41, in <module>
key = keygen(seed)
File "beer.py", line 14, in keygen
secret = str(uint32(1751873395 * magic))
OverflowError: Python int too large to convert to C long
python
1
Are you sure you need to useuint32here:uint32(1751873395 * magic)? Python's native integers can, in contrast withnumpy.uint32, be as large as your RAM allows.
– ForceBru
Jan 20 at 11:41
add a comment |
Im using windows 10 to generate a security code for my DVR that i forgot the password.
Installed Python 3.7.2 on my Notebook
RAM:16GB
HDD:1TB
#!/usr/bin/env python3
import sys
from re import search
from numpy import uint32
from requests import get
from datetime import datetime
def keygen(seed):
magic = 0
for i, char in enumerate(seed):
i += 1
magic += i * ord(char) ^ i
secret = str(uint32(1751873395 * magic))
c = str.maketrans("012345678", "QRSqrdeyz")
return secret.translate(c)
def get_serial_date(ip):
try:
req = get("http://192.168.178.43/upnpdevicedesc.xml")
except Exception as e:
print("Unable to connect to {ip}:n{e}")
sys.exit(-1)
model = search("<modelNumber>(.*)</modelNumber>", req.text).group(1)
serial = search("<serialNumber>(.*)</serialNumber>", req.text).group(1)
serial = serial.replace(model, "")
datef = datetime.strptime(req.headers["Date"], "%a, %d %b %Y %H:%M:%S GMT")
date = datef.strftime("%Y%m%d")
return "{serial}{date}"
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: {sys.argv[0]} <ip>")
print("Connects to a device and generates a security key")
sys.exit(1)
seed = get_serial_date(sys.argv[1])
print("Got seed: {seed}")
key = keygen(seed)
print("Generated security key: {key}")
is there a way to fix this error code or i need to do something with my Notebook Settins?
Here is the error code that i get
Got seed: {seed}
Traceback (most recent call last):
File "beer.py", line 41, in <module>
key = keygen(seed)
File "beer.py", line 14, in keygen
secret = str(uint32(1751873395 * magic))
OverflowError: Python int too large to convert to C long
python
Im using windows 10 to generate a security code for my DVR that i forgot the password.
Installed Python 3.7.2 on my Notebook
RAM:16GB
HDD:1TB
#!/usr/bin/env python3
import sys
from re import search
from numpy import uint32
from requests import get
from datetime import datetime
def keygen(seed):
magic = 0
for i, char in enumerate(seed):
i += 1
magic += i * ord(char) ^ i
secret = str(uint32(1751873395 * magic))
c = str.maketrans("012345678", "QRSqrdeyz")
return secret.translate(c)
def get_serial_date(ip):
try:
req = get("http://192.168.178.43/upnpdevicedesc.xml")
except Exception as e:
print("Unable to connect to {ip}:n{e}")
sys.exit(-1)
model = search("<modelNumber>(.*)</modelNumber>", req.text).group(1)
serial = search("<serialNumber>(.*)</serialNumber>", req.text).group(1)
serial = serial.replace(model, "")
datef = datetime.strptime(req.headers["Date"], "%a, %d %b %Y %H:%M:%S GMT")
date = datef.strftime("%Y%m%d")
return "{serial}{date}"
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: {sys.argv[0]} <ip>")
print("Connects to a device and generates a security key")
sys.exit(1)
seed = get_serial_date(sys.argv[1])
print("Got seed: {seed}")
key = keygen(seed)
print("Generated security key: {key}")
is there a way to fix this error code or i need to do something with my Notebook Settins?
Here is the error code that i get
Got seed: {seed}
Traceback (most recent call last):
File "beer.py", line 41, in <module>
key = keygen(seed)
File "beer.py", line 14, in keygen
secret = str(uint32(1751873395 * magic))
OverflowError: Python int too large to convert to C long
python
python
asked Jan 20 at 11:38
nullsoft pikanullsoft pika
11
11
1
Are you sure you need to useuint32here:uint32(1751873395 * magic)? Python's native integers can, in contrast withnumpy.uint32, be as large as your RAM allows.
– ForceBru
Jan 20 at 11:41
add a comment |
1
Are you sure you need to useuint32here:uint32(1751873395 * magic)? Python's native integers can, in contrast withnumpy.uint32, be as large as your RAM allows.
– ForceBru
Jan 20 at 11:41
1
1
Are you sure you need to use
uint32 here: uint32(1751873395 * magic)? Python's native integers can, in contrast with numpy.uint32, be as large as your RAM allows.– ForceBru
Jan 20 at 11:41
Are you sure you need to use
uint32 here: uint32(1751873395 * magic)? Python's native integers can, in contrast with numpy.uint32, be as large as your RAM allows.– ForceBru
Jan 20 at 11:41
add a comment |
1 Answer
1
active
oldest
votes
If you use uint32 to reduce the number to the range 0 … 2**32-1, you could use this instead:
secret = str((1751873395 * magic) & 0xffffffff)
Also note that using enumerate in combination with i += 1 in the loop is very confusing.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54276046%2fhow-to-fix-python-int-too-large-to-convert-to-c-long%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you use uint32 to reduce the number to the range 0 … 2**32-1, you could use this instead:
secret = str((1751873395 * magic) & 0xffffffff)
Also note that using enumerate in combination with i += 1 in the loop is very confusing.
add a comment |
If you use uint32 to reduce the number to the range 0 … 2**32-1, you could use this instead:
secret = str((1751873395 * magic) & 0xffffffff)
Also note that using enumerate in combination with i += 1 in the loop is very confusing.
add a comment |
If you use uint32 to reduce the number to the range 0 … 2**32-1, you could use this instead:
secret = str((1751873395 * magic) & 0xffffffff)
Also note that using enumerate in combination with i += 1 in the loop is very confusing.
If you use uint32 to reduce the number to the range 0 … 2**32-1, you could use this instead:
secret = str((1751873395 * magic) & 0xffffffff)
Also note that using enumerate in combination with i += 1 in the loop is very confusing.
answered Jan 20 at 12:38
Florian WeimerFlorian Weimer
15.8k31145
15.8k31145
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54276046%2fhow-to-fix-python-int-too-large-to-convert-to-c-long%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Are you sure you need to use
uint32here:uint32(1751873395 * magic)? Python's native integers can, in contrast withnumpy.uint32, be as large as your RAM allows.– ForceBru
Jan 20 at 11:41