Skip to content

Instantly share code, notes, and snippets.

@skikozou
Last active January 4, 2025 15:02
Show Gist options
  • Save skikozou/bbfd63f1e79976b5e0f2d1bb91ab663f to your computer and use it in GitHub Desktop.
Save skikozou/bbfd63f1e79976b5e0f2d1bb91ab663f to your computer and use it in GitHub Desktop.
Android Pattern Bruteforce
package main
import "fmt"
func main() {
fmt.Println("Android Pattern Bruteforce")
//初期化
UsedPoint := []int{}
PasswordCount := 0
PointInit()
//各点ごとにぶん回す
for i := 0; i < 9; i++ {
maxLen = i + 1
for _, v := range StartPoint {
TreeSearch(v, UsedPoint, &PasswordCount)
}
}
fmt.Println(PasswordCount)
}
var IsDebug = true
var maxLen = 0
func Debug(data any) {
if IsDebug {
fmt.Println(data)
}
}
func TreeSearch(point *Point, UsedPoint []int, PasswordCount *int) {
UsedPoint = append(UsedPoint, point.position)
//使用済みのポイントから新たに使用可能になったポイントを追加 (例 2を使ったとき、1から3に行ける)
PointUpdate(UsedPoint)
if len(UsedPoint) >= 9 || len(UsedPoint) >= maxLen {
//使用済みポイントが9個以上 or 使用可能な最大ポイント数を超えたとき
*PasswordCount++
Debug(UsedPoint)
PointInit()
return
}
UsedPointCount := 0
PointCount := len(point.next)
forBreak:
for _, v := range point.next {
if CheckUsed(UsedPoint, v.position) {
UsedPointCount++
continue forBreak
}
TreeSearch(v, UsedPoint, PasswordCount)
}
if UsedPointCount >= PointCount {
//すべてのポイントが使用済みでアクセスできなかったら
*PasswordCount++
Debug(UsedPoint)
PointInit()
return
}
}
func CheckUsed(UsedPoint []int, num int) bool {
for _, v := range UsedPoint {
if num == v {
return true
}
}
return false
}
func PointUpdate(UsedPoint []int) {
for _, p := range UsedPoint {
switch p {
case 2:
P1.next = append(P1.next, &P3)
P3.next = append(P3.next, &P1)
case 4:
P1.next = append(P1.next, &P7)
P7.next = append(P7.next, &P1)
case 5:
P1.next = append(P1.next, &P9)
P3.next = append(P3.next, &P7)
P4.next = append(P4.next, &P6)
P2.next = append(P2.next, &P8)
P9.next = append(P9.next, &P1)
P7.next = append(P7.next, &P3)
P6.next = append(P6.next, &P4)
P8.next = append(P8.next, &P2)
case 6:
P9.next = append(P9.next, &P3)
P3.next = append(P3.next, &P9)
case 8:
P9.next = append(P9.next, &P7)
P7.next = append(P7.next, &P9)
}
}
}
func PointInit() {
P1 = Point{1, []*Point{&P2, &P4, &P5, &P6, &P8}}
P2 = Point{2, []*Point{&P1, &P3, &P4, &P5, &P6, &P7, &P9}}
P3 = Point{3, []*Point{&P2, &P4, &P5, &P6, &P8}}
P4 = Point{4, []*Point{&P1, &P2, &P3, &P5, &P7, &P8, &P9}}
P5 = Point{5, []*Point{&P1, &P2, &P3, &P4, &P6, &P7, &P8, &P9}}
P6 = Point{6, []*Point{&P1, &P2, &P3, &P5, &P7, &P8, &P9}}
P7 = Point{7, []*Point{&P2, &P4, &P5, &P6, &P8}}
P8 = Point{8, []*Point{&P1, &P3, &P4, &P5, &P6, &P7, &P9}}
P9 = Point{9, []*Point{&P2, &P4, &P5, &P6, &P8}}
}
type Point struct {
position int
next []*Point
}
var StartPoint []*Point = []*Point{&P1, &P2, &P3, &P4, &P5, &P6, &P7, &P8, &P9}
var (
P1,
P2,
P3,
P4,
P5,
P6,
P7,
P8,
P9 Point
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment