Skip to content

Instantly share code, notes, and snippets.

@mebiusbox
Last active September 1, 2024 18:32
Show Gist options
  • Save mebiusbox/3d280cdd73fcc11ef129ebe532b648e4 to your computer and use it in GitHub Desktop.
Save mebiusbox/3d280cdd73fcc11ef129ebe532b648e4 to your computer and use it in GitHub Desktop.
Passcard Generator

Passcard Generator

PowerShellでパスワード用のコード表(16x16)を生成します.

Usage

PS > New-Passcard [-Uppercase] [-Lowercase] [-Number] [-Symbol] [-NoSimilar] [-Separtor] [-Seed <int>]
Option Description
Uppercase 大文字のアルファベット
Lowercase 小文字のアルファベット
Number 数字
Symbol !@#$%^&*+
NoSimilar il1LoO0を除外
Separator 8行目にセパレータを表示
Seed シード値

Examples

PS > New-Passcard -Uppercase -Lowercase -Number -Symbol -NoSimilar -Separator -Seed 1234
    0 1 2 3 4 5 6 7 8 9 A B C D E F
-----------------------------------
0 | k D & j n D g W x H A X n F D F
1 | m v p % F u 4 X j J 3 f E f c 5
2 | # J 3 v 3 B M W & 8 U T 3 S x s
3 | G y u A X & J Z @ W V B H x 7 r
4 | h P x 6 7 v * C U H q C f 8 c T
5 | F w D g x A G J 5 7 H + g & * M
6 | A v m N W y & % ! S T 2 P b v n
7 | C % S 2 3 ^ E W b a j a K D z x
-----------------------------------
8 | q s N u Z $ V u x v t y ! q R q
9 | e ! b 5 # 9 K 3 X w k $ J a V 9
A | q t n S h D X % W 9 p q b s ^ %
B | w m ^ h b a c ! H W y n Z V % #
C | Q J V n w $ y p 7 x V ^ a m S y
D | e A 5 8 Y * E @ K A X A f * g t
E | N V v A j % m F P V n Z g H ^ +
F | c p H U q W C q 3 % j m h j p w
PS > New-Passcard -Uppercase -Lowercase -Number -Symbol -NoSimilar -Seed 1234
    0 1 2 3 4 5 6 7 8 9 A B C D E F
-----------------------------------
0 | k D & j n D g W x H A X n F D F
1 | m v p % F u 4 X j J 3 f E f c 5
2 | # J 3 v 3 B M W & 8 U T 3 S x s
3 | G y u A X & J Z @ W V B H x 7 r
4 | h P x 6 7 v * C U H q C f 8 c T
5 | F w D g x A G J 5 7 H + g & * M
6 | A v m N W y & % ! S T 2 P b v n
7 | C % S 2 3 ^ E W b a j a K D z x
8 | q s N u Z $ V u x v t y ! q R q
9 | e ! b 5 # 9 K 3 X w k $ J a V 9
A | q t n S h D X % W 9 p q b s ^ %
B | w m ^ h b a c ! H W y n Z V % #
C | Q J V n w $ y p 7 x V ^ a m S y
D | e A 5 8 Y * E @ K A X A f * g t
E | N V v A j % m F P V n Z g H ^ +
F | c p H U q W C q 3 % j m h j p w
PS > New-Passcard -Uppercase -Lowercase -Number -Seed 1234
    0 1 2 3 4 5 6 7 8 9 A B C D E F
-----------------------------------
0 | g D 7 e h D c T q H A T i F D F
1 | f p i 5 F n v U e I u c E c Z w
2 | 3 I u p u B K T 7 z R Q u P q l
3 | G r o A U 7 I W 2 T S B H r z k
4 | d M q y x o 8 C Q H k C c 0 Z P
5 | F p D d q A G I w y H 9 d 7 8 K
6 | A q h L T r 7 5 1 P Q t M X o h
7 | C 5 P t u 6 E S X Y e X J D s q
8 | j l L n W 4 R o q o m s 1 j O j
9 | b 2 X w 3 0 J u U p g 4 I W R 0
A | k m h O e D T 5 T 0 i j X l 6 5
B | p g 6 e X W Z 1 H T r i W R 5 3
C | N I R h p 4 s j z q R 6 X h P r
D | a A w 0 V 8 E 2 I A U A c 8 c m
E | K R p A e 5 h F M S i W d H 6 9
F | Y j H R j T C k u 6 f h e d i q
PS > New-Passcard -Uppercase -Number -Seed 1234
    0 1 2 3 4 5 6 7 8 9 A B C D E F
-----------------------------------
0 | S B 8 R T C Q L Y E A L T C D E
1 | T X U 7 C X 1 M R F 1 Q C Q O 2
2 | 6 E 0 X 1 A G L 8 3 K J 0 I Y W
3 | D Z X A L 8 E N 5 L M A E Z 3 V
4 | R H Y 3 2 X 9 B J E U B Q 4 O J
5 | C Y B Q Y A D E 2 3 E 9 R 8 9 G
6 | A X T G L Z 8 7 4 I J 0 H N X T
7 | B 7 I 0 1 7 C K N O R N F B Z Y
8 | U V G W M 8 K X Y X W Z 5 U I U
9 | P 5 N 2 6 4 F 0 L Y S 6 E N K 4
A | U W T I R C L 7 M 4 U V N W 8 7
B | Y S 7 R N O P 5 E L Z T M K 7 6
C | H E K T Y 7 Z U 3 Y K 8 N T I Z
D | P A 2 4 M 9 C 5 F A L A Q 8 Q W
E | G K X A R 7 T D H K T M R E 7 9
F | O U E K U L B V 0 7 S T S R U Y

懸念事項

  • PowerShell内部(Get-Random)の乱数アルゴリズムや仕様が変わるとシード値が同じでも結果が変わる可能性があります
function New-Passcard() {
param(
[switch]$Uppercase,
[switch]$Lowercase,
[switch]$Number,
[switch]$Symbol,
[switch]$NoSimilar,
[switch]$Separator,
[int]$Seed
)
$uppercaseTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
$lowercaseTable = "abcdefghijklmnopqrstuvwxyz"
$numberTable = "0123456789"
$symbolTable = "!@#$%^&*+"
$similarTable = "il1LoO0"
$table = ""
if ($Uppercase) {
$table += $uppercaseTable
}
if ($Lowercase) {
$table += $lowercaseTable
}
if ($Number) {
$table += $numberTable
}
if ($Symbol) {
$table += $symbolTable
}
if ($NoSimilar) {
$table = $table -replace "[$similarTable]",""
}
$len = $table.Length
$seeds = @()
if ($Seed) {
$seeds = Get-Random -Count 16 -SetSeed $Seed
} else {
$seeds = Get-Random -Count 16
}
# 16x16
$card = @{}
for ($i=0; $i -lt 16; $i++) {
$card[$i] = ""
$indices = Get-Random -Maximum $len -Count 16 -SetSeed $seeds[$i]
for ($j=0; $j -lt 16; $j++) {
# 少なくとも上と左の文字と同じにならないようにする
# Ensure that the letters above and to the left are not the same.
$exclude = @()
if ($i -gt 0) {
$exclude += $card[$i-1][$j]
}
if ($j -gt 0) {
$exclude += $card[$i][$j-1]
}
$k = 0
do {
$c = $table[($indices[$j]+$k) % $len]
$k++
} while ($exclude.Contains($c))
$card[$i] += $c
}
}
Write-Output " 0 1 2 3 4 5 6 7 8 9 A B C D E F"
Write-Output "-----------------------------------"
for ($i=0; $i -lt 16; $i++) {
if ($Separator -and $i -eq 8) {
Write-Output "-----------------------------------"
}
$s = "{0:X} |" -f $i
$s += $card[$i] -replace "(.)"," `$1"
Write-Output $s
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment