In [1]:
library(digest)
In [2]:
input <- "wtnhxymk"
In [3]:
tmp <- 0
hashes <- integer()
password <- integer()
advancedCode <- c(rep(NA, 8))
while(anyNA(advancedCode)) { #Pas le best skill de R de faire des loop de MD5...
x <- digest(paste(input,tmp,sep=""),"md5", serialize = FALSE)
if (startsWith(x,"00000")){
hashes <- c(hashes,tmp)# Keep list of working number to add to the password
password <- c(password,substr(x,6,6))
posi <- strtoi(substr(x,6,6), base = 16L)
if(posi < 8 & is.na(advancedCode[posi+1])){
advancedCode[posi+1] <- substr(x,7,7)
}
}
tmp <- tmp +1
}
In [4]:
cat("Q1 - Password for the door is: ", paste(password[1:8],collapse=""), '\n')
cat("Q2 - Password for the second door is: ", paste(advancedCode,collapse=""), '\n')