Python Forum
coding error from a script (absolute noob)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
coding error from a script (absolute noob)
#1
hi, im trying to figure out a script here, it gives me error
TypeError: unsupported operand type(s) for &: 'float' and 'int'

script is from http://dogber1.blogspot.com/2009/05/tabl...-bios.html
ive fixed initial error from raw_input to input but cant figure out other stuff

im using pyton 3.7 under windows

heres the working part of the code below :

import os

# someone smacked his head onto the keyboard
XORkey = "<7#&9?>s"

def codeToBytes(code):
	numbers = (int(code[0:5]), int(code[5:10]), int(code[10:15]), int(code[15:20]))
	bytes = []
	for i in numbers:
		bytes.append(i % 256)
		bytes.append(i / 256)
	return bytes 

def byteToChar(byte):
	if byte > 9:
		return chr(ord('a') + byte - 10)
	else:
		return chr(ord('0') + byte)

def decryptCode(bytes):
	# swap two bytes
	#bytes[2], bytes[6] = bytes[6], bytes[2]
	#bytes[3], bytes[7] = bytes[7], bytes[3]

	# interleave the nibbles 
	bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7] = ((bytes[3] & 0xF0) | (bytes[0]  & 0x0F), (bytes[2] & 0xF0) | (bytes[1] & 0x0F), (bytes[5] & 0xF0) | (bytes[6] & 0x0F), (bytes[4] & 0xF0) | (bytes[7] & 0x0F), (bytes[7] & 0xF0) | (bytes[4] & 0x0F), (bytes[6] & 0xF0) | (bytes[5] & 0x0F), (bytes[1] & 0xF0)  | (bytes[2] & 0x0F), (bytes[0] & 0xF0) | (bytes[3] & 0x0F))

	# apply XOR key
	for i in range(len(bytes)):
		bytes[i] = bytes[i] ^ ord(XORkey[i])

	# final rotations
	bytes[0] = ((bytes[0] << 1) & 0xFF) | (bytes[0] >> 7)
	bytes[1] = ((bytes[1] << 7) & 0xFF) | (bytes[1] >> 1)
	bytes[2] = ((bytes[2] << 2) & 0xFF) | (bytes[2] >> 6)
	bytes[3] = ((bytes[3] << 8) & 0xFF) | (bytes[3] >> 0)
	bytes[4] = ((bytes[4] << 3) & 0xFF) | (bytes[4] >> 5)
	bytes[5] = ((bytes[5] << 6) & 0xFF) | (bytes[5] >> 2)
	bytes[6] = ((bytes[6] << 4) & 0xFF) | (bytes[6] >> 4)
	bytes[7] = ((bytes[7] << 5) & 0xFF) | (bytes[7] >> 3)

	# len(solution space) = 10+26
	bytes = [x % 36 for x in bytes]

	masterPwd = ""
	for x in bytes:
		masterPwd += byteToChar(x)
	return masterPwd

print("Master Password Generator for FSI laptops (6x4 digits version)")
print("Copyright (C) 2013 dogbert <[email protected]>")
print("")
print("When asked for a password, enter these:")
print("First password:  3hqgo3")
print("Second password: jqw534")
print("Third password:  0qww294e")
print("")
print("You will receive a hash code with five blocks, each with four numbers, ")
print("e.g. 1234-4321-1234-4321-1234")
print("")
print("Please enter the hash: ")
inHash = input().strip().replace('-', '').replace(' ', '')
inHash = inHash[4:]
password = decryptCode(codeToBytes(inHash))
print("")
print("The master password is: " + password)
print("")
print("Please note that the password is encoded for US QWERTY keyboard layouts.")
if (os.name == 'nt'):
	print("Press a key to exit...")
	input()
i absolutely need it to generate password bios for my 3 months stowed away laptop

thank you
Reply
#2
I haven't dug into it deeply, but I suspect that
bytes.append(i / 256)
should be
bytes.append(int(i / 256))
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Reply
#3
This is a code which works


#!/usr/bin/python

# Copyright 2009:  dogbert <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
# This script generates master passwords which can be used to unlock
# the BIOS passwords of most Fujitsu Siemens laptops (Lifebook, Amilo etc.).
# You have to install python for running this script.

import os

# someone smacked his head onto the keyboard
XORkey = "<7#&9?>s"

def codeToBytes(code):
	numbers = (int(code[0:5]), int(code[5:10]), int(code[10:15]), int(code[15:20]))
	bytes = []
	for i in numbers:
		bytes.append(int(i % 256))
		bytes.append(int(i / 256))
	return bytes 

def byteToChar(byte):
	if byte > 9:
		return chr(ord('a') + byte - 10)
	else:
		return chr(ord('0') + byte)

def decryptCode(bytes):
	# swap two bytes
	#bytes[2], bytes[6] = bytes[6], bytes[2]
	#bytes[3], bytes[7] = bytes[7], bytes[3]

	# interleave the nibbles 
	bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7] = ((bytes[3] & 0xF0) | (bytes[0]  & 0x0F), (bytes[2] & 0xF0) | (bytes[1] & 0x0F), (bytes[5] & 0xF0) | (bytes[6] & 0x0F), (bytes[4] & 0xF0) | (bytes[7] & 0x0F), (bytes[7] & 0xF0) | (bytes[4] & 0x0F), (bytes[6] & 0xF0) | (bytes[5] & 0x0F), (bytes[1] & 0xF0)  | (bytes[2] & 0x0F), (bytes[0] & 0xF0) | (bytes[3] & 0x0F))

	# apply XOR key
	for i in range(len(bytes)):
		bytes[i] = bytes[i] ^ ord(XORkey[i])

	# final rotations
	bytes[0] = ((bytes[0] << 1) & 0xFF) | (bytes[0] >> 7)
	bytes[1] = ((bytes[1] << 7) & 0xFF) | (bytes[1] >> 1)
	bytes[2] = ((bytes[2] << 2) & 0xFF) | (bytes[2] >> 6)
	bytes[3] = ((bytes[3] << 8) & 0xFF) | (bytes[3] >> 0)
	bytes[4] = ((bytes[4] << 3) & 0xFF) | (bytes[4] >> 5)
	bytes[5] = ((bytes[5] << 6) & 0xFF) | (bytes[5] >> 2)
	bytes[6] = ((bytes[6] << 4) & 0xFF) | (bytes[6] >> 4)
	bytes[7] = ((bytes[7] << 5) & 0xFF) | (bytes[7] >> 3)

	# len(solution space) = 10+26
	bytes = [x % 36 for x in bytes]

	masterPwd = ""
	for x in bytes:
		masterPwd += byteToChar(x)
	return masterPwd

print("Master Password Generator for FSI laptops (6x4 digits version)")
print("Copyright (C) 2013 dogbert <[email protected]>")
print("")
print("When asked for a password, enter these:")
print("First password:  3hqgo3")
print("Second password: jqw534")
print("Third password:  0qww294e")
print("")
print("You will receive a hash code with five blocks, each with four numbers, ")
print("e.g. 1234-4321-1234-4321-1234")
print("")
print("Please enter the hash: ")
inHash = input().strip().replace('-', '').replace(' ', '')
inHash = inHash[4:]
password = decryptCode(codeToBytes(inHash))
print("")
print("The master password is: " + password)
print("")
print("Please note that the password is encoded for US QWERTY keyboard layouts.")
if (os.name == 'nt'):
	print("Press a key to exit...")
	input()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python coding error isntitzee 1 289 Oct-17-2020, 06:30 AM
Last Post: buran
  Coding error- Not sure where I have put error markers against the code that is wrong Username9 1 286 Sep-28-2020, 07:57 AM
Last Post: buran
  coding error iro a menu Rollo 2 406 Sep-27-2020, 04:17 PM
Last Post: deanhystad
  Absolute beginner am I missing something? kamren 7 472 Sep-25-2020, 05:32 AM
Last Post: buran
  chkFile with absolute paths JarredAwesome 7 389 Sep-21-2020, 03:51 AM
Last Post: bowlofred
  Adafruit LIS3DH coding error FitDad73 1 346 Aug-30-2020, 01:37 AM
Last Post: bowlofred
  absolute imports between folders mikisDW 0 287 Aug-05-2020, 12:26 PM
Last Post: mikisDW
  I am an absolute newbie.Help me! feynarun 4 557 Apr-11-2020, 09:25 PM
Last Post: feynarun
  Coding error- help FatherYeals 3 639 Mar-27-2020, 02:11 PM
Last Post: deanhystad
  name undefined Coding Error Ewilliam51 2 581 Feb-06-2020, 12:19 AM
Last Post: Ewilliam51

Forum Jump:

User Panel Messages

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