I'm trying to make an AI that can discern between making a typo when putting in your phone's password and trying to guess someone's password. While programming this, I encountered a problem. Here is my code so far:
from random import random
synapses = {}
mainc = 0
while mainc < 80:
mainc += 1
synapses[mainc] = random()
def findtrain(original, tbtested):
print "this function does nothing yet"
def find(original, tbtested):
input_d1 = {1 : 0, 2 : 0, 3 : 0, 4 : 0, 5 : 0, 6 : 0, 7 : 0, 8 : 0, 9 : 0, 0 : 0}
input_d2 = {1 : 0, 2 : 0, 3 : 0, 4 : 0, 5 : 0, 6 : 0, 7 : 0, 8 : 0, 9 : 0, 0 : 0}
input_d3 = {1 : 0, 2 : 0, 3 : 0, 4 : 0, 5 : 0, 6 : 0, 7 : 0, 8 : 0, 9 : 0, 0 : 0}
input_d4 = {1 : 0, 2 : 0, 3 : 0, 4 : 0, 5 : 0, 6 : 0, 7 : 0, 8 : 0, 9 : 0, 0 : 0}
input_d1_actual = {1 : 0, 2 : 0, 3 : 0, 4 : 0, 5 : 0, 6 : 0, 7 : 0, 8 : 0, 9 : 0, 0 : 0}
input_d2_actual = {1 : 0, 2 : 0, 3 : 0, 4 : 0, 5 : 0, 6 : 0, 7 : 0, 8 : 0, 9 : 0, 0 : 0}
input_d3_actual = {1 : 0, 2 : 0, 3 : 0, 4 : 0, 5 : 0, 6 : 0, 7 : 0, 8 : 0, 9 : 0, 0 : 0}
input_d4_actual = {1 : 0, 2 : 0, 3 : 0, 4 : 0, 5 : 0, 6 : 0, 7 : 0, 8 : 0, 9 : 0, 0 : 0}
joined = int(str(original) + str(tbtested))
c1 = 0
while c1 < 4:
c1 += 1
#I think that the problem is coming from this line vvv and
exec("input_d%s[int(str(joined)[c1]) - 1] = 1" % (str(c1)))
c1 = 0
while c1 < 4:
c1 += 1
#this line vvv
exec("input_d%s_actual[int(str(joined)[c1]) - 1] = 1" % (str(c1)))
#I used the following line to test the dictionary's values
print input_d4
print "Welcome to my AI. The purpose of this AI is to be able to discern between a typo when typing in your password and someone guessing random passwords to attempt to get into your account/device. At the present, it only accepts 4-digit numeral passwords."
if raw_input("Would you like to train?")[0] == "y":
password_original = raw_input("Please enter the ACTUAL four digit password.")
password_typo_guess = raw_input("Now enter a 4 digit password that is either a typo or an attempt at guessing the password. The AI will attempt to figure out which one it is.")
findtrain(password_original, password_typo_guess)
else:
password_original = raw_input("Please enter the ACTUAL four digit password.")
password_typo_guess = raw_input("Now enter a 4 digit password that is either a typo or an attempt at guessing the password. The AI will attempt to figure out which one it is.")
find(password_original, password_typo_guess)
Each input-d _n_
represents each digit of the original password. The input-d _n_ - actual
represent each digit of the password that the AI is testing. There are ten keys in each dictionary, because I need a value between 0 and 1. If the first digit of my password were '7', I would set input-d1[7]
to 1, and all of input-d1's
other entries to 0.
Now, here's where we get to the problem. When prompted for the ORIGINAL password, I enter 1234 and I put the same thing for the password to be tested. For testing purposes, I have a command to print input-d4
in _find_
. You'd think that it would print {1 : 0, 2 : 0, 3 : 0, 4 : 1, 5 : 0, 6 : 0, 7 : 0, 8 : 0, 9 : 0, 0 : 0}
, but it doesn't. It prints {0 : 1, 1 : 0, 2 : 0, 3 : 0, 4 : 0, 5 : 0, 6 : 0, 7 : 0, 8 : 0, 9 : 0}
.
The weird thing, though, is that this only happens on d4
and d4 actual
. All of the other digits are just fine. And I've tried with multiple different password inputs. For some reason, on the fourth digit, it always subtracts by 4.
For example, if the fourth digit is 8, it will say that the fourth digit is 4. I could write something to automatically add four, but I would prefer to know exactly what's wrong. Maybe it's the compiler I'm using (an online one). I've looked through this code time and time again and I haven't figured out what was causing this. If you think you know why this isn't working, please share. I hope I did a good job explaining.