首页 > 解决方案 > R密码分析

问题描述

我想分析一个 uni 项目的密码。我想给 R 50 个密码进行分析,查看小写、大写、数字和特殊字符的组合。我正在使用一些来自https://datadrivensecurity.info/blog/posts/2014/Feb/ripal/的 R 代码,但我无法让它工作。

具体来说,R 只能识别小写字母密码,我无法识别具有其他字符组合的密码,例如大写和小写,小写和特殊等,当我知道有密码时,代码一直以 0% 出现符合我数据框中 50 个标准的密码。

我做错了什么,我的论点/R代码是否正确?

非常感谢任何帮助。

  contains.only.lower.alpha <- sum(grepl("^[a-z]+$",Final_DF$Pswd))
contains.only.upper.alpha <- sum(grepl("^[A-Z]+$",Final_DF$Pswd))
contains.only.numeric <- sum(grepl("^[0-9]+$",Final_DF$Pswd))
contains.only.special <- sum(grepl("^[:punct:]+$",Final_DF$Pswd))

contains.both.lower.and.upper <- only.lower.alpha + only.upper.alpha
contains.both.lower.and.numeric <- only.lower.alpha + only.numeric
contains.both.lower.and.special <- only.lower.alpha + only.special
contains.both.upper.and.numeric <- only.upper.alpha + only.numeric
contains.both.upper.and.special <- only.upper.alpha + only.special
contains.both.numeric.and.special <- only.numeric + only.special

contains.lower.upper.and.numeric <- only.lower.alpha + only.upper.alpha + only.numeric
contains.lower.upper.numeric.and.special <- only.lower.alpha + only.upper.alpha + only.numeric + only.special

print(sprintf("Only lowercase alpha = %d, (%3.3f%%)", only.lower.alpha, 100*(only.lower.alpha/50)))
print(sprintf("Only uppercase alpha = %d, (%3.3f%%)", only.upper.alpha, 100*(only.upper.alpha/50)))
print(sprintf("Only numeric = %d, (%3.3f%%)", only.numeric, 100*(only.numeric/50)))
print(sprintf("Only special = %d, (%3.3f%%)", only.special, 100*(only.special/50)))

print(sprintf("Both lower and upper alpha = %d, (%3.3f%%)", both.lower.and.upper, 100*(both.lower.and.upper/50)))
print(sprintf("Both lower and numeric = %d, (%3.3f%%)", both.lower.and.numeric, 100*(both.lower.and.numeric/50)))
print(sprintf("Both lower and special = %d, (%3.3f%%)", both.lower.and.special, 100*(both.lower.and.special/50)))
print(sprintf("Both upper and numeric = %d, (%3.3f%%)", both.upper.and.numeric, 100*(both.upper.and.numeric/50)))
print(sprintf("Both upper and special = %d, (%3.3f%%)", both.upper.and.special, 100*(both.upper.and.special/50)))
print(sprintf("Both.numeric.and.special = %d, (%3.3f%%)", both.numeric.and.special, 100*(both.numeric.and.special/50)))

print(sprintf("Lower.upper.and.numeric = %d, (%3.3f%%)", lower.upper.and.numeric, 100*(lower.upper.and.numeric/50)))
print(sprintf("Lower.upper.numeric.and.special = %d, (%3.3f%%)", lower.upper.numeric.and.special, 100*(lower.upper.numeric.and.special/50)))

这些是我正在使用的 50 个密码,它们是我使用 R 生成的,在我知道我可以让代码工作之后,我将重新生成这些密码以获得更大的传播,以包括所有特殊等。

> Final_DF$Pswd

[1] "monkey" "iloveyou" "dragon" "jbI2pnK$xi" "password" "computer" "!qessw"
[8] "tUNh&SSm6!" “阳光”“wYrUeWV”“超人”“三星”“utoXGe6$”“大师”
[15]“wjZC&OvXX”“0R1cNTm9sGir”“Fbuu2bs89?” “口袋妖怪”“秘密”“x&W1TjO59”“克星”
[22]“紫色”“闪耀”“花”“码头”“Tg%OQT$0”“SbDUV&nOX”“花生”
[29]“天使”“?1LOEc4Zfk”“电脑” ”


标签: rpasswordsanalytics

解决方案


想通了,每个密码字符组合所需的逻辑语句组合

grepl("^(?!.*[[:lower:]]).*$",df, perl = TRUE)

推荐阅读