Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let changeDigit(position:int)(newDigit: Nat)(password: Nat List):Nat List = //changes list element on "position" to "newDigit"
- let mutable passwordArray = Array.ofList(password)
- let mutable passwordList = password
- let mutable oldDigit = passwordArray.[position]
- let mutable i = 10N-newDigit
- while i > 0N do
- oldDigit <- (oldDigit-1N)
- i <- (i-1N)
- passwordArray.[position-1] <- oldDigit
- passwordList <- List.ofArray(passwordArray)
- passwordList
- let rec crackPassword(password: Nat List)(secret: Secret) = //finds out correct digits one by one
- let mutable crackedPassword = password
- let mutable stelle = 0
- let mutable ziffer = 0N
- let mutable oldP = 0N
- let mutable oldD = 0N
- // I don't know what I'm doing from here
- // try unlock crackedPassword secret with
- // |WrongPassword(p, d) -> if p > oldP then
- // crackedPassword <- (changeDigit stelle ziffer crackedPassword)
- // oldP <- (oldP+1N)
- // stelle <- (stelle+1)
- // crackPassword crackedPassword secret
- // elif d > oldD then
- (*
- I'm writing a program to "crack" a password of numbers between 0-9 (represented as a list) using exception handling. The function unlock (password: Nat list) (s: Secret): String throws a WrongPassword(p, d) exception on a wrong password input, where p is the number of correct numbers in correct positions, and d the number of overall correct numbers. For now I have a function that determines the length of the password and fills the elements of the list with 10's. The changeDigit function takes a list and changes an element on a chosen position to a chosen number. I want to use the changeDigit function to find out the correct numbers one by one unsing the information from WrongPassword(p, d) but the implementation of the function confuses me a lot. I want the try the start with the first position in the list and increase the number by one everytime the exception is thrown until p increases by 1. I then want to continue with the next position in the list. A further optimization would be to use d to try all positions until p increases by 1. I'm trying to realise my idea in the crackPassword function, but I can't figure out how to write a working loop with the exception handling.
- *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement