This repository was archived by the owner on Aug 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +77
-0
lines changed
Expand file tree Collapse file tree 2 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "fmt"
5+ "os"
6+ "strconv"
7+ "strings"
8+ )
9+
10+ func Maskify (cc string ) string {
11+ var masked = make ([]string , len (cc ))
12+ var splitted = strings .Split (cc , "" )
13+
14+ for idx , item := range splitted {
15+ // Exclude first and last four items
16+ if idx == 0 || idx >= len (splitted ) - 4 {
17+ masked = append (masked , item )
18+ continue
19+ }
20+
21+ // Check if is numeric
22+ _ , err := strconv .Atoi (item )
23+
24+ if err != nil {
25+ masked = append (masked , item )
26+ continue
27+ }
28+
29+ masked = append (masked , "#" )
30+ }
31+
32+ return strings .Join (masked , "" )
33+ }
34+
35+ func main () {
36+ cc := ""
37+
38+ if len (os .Args ) > 1 {
39+ cc = os .Args [1 ]
40+ } else {
41+ os .Exit (0 )
42+ }
43+
44+ // Do no mask if cc less than 6 or empty string
45+ if len (cc ) < 6 {
46+ fmt .Println (cc )
47+ os .Exit (0 )
48+ }
49+
50+ fmt .Printf (Maskify (cc ))
51+ }
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "reflect"
5+ "testing"
6+ )
7+
8+ func TestMaskify (t * testing.T ) {
9+ type test struct {
10+ input string
11+ want string
12+ }
13+
14+ tests := []test {
15+ {input : "12345" , want : "12345" },
16+ {input : "1234-4567-8901" , want : "1###-####-8901" },
17+ {input : "123456789" , want : "1####6789" },
18+ }
19+
20+ for _ , tc := range tests {
21+ got := Maskify (tc .input )
22+ if ! reflect .DeepEqual (tc .want , got ) {
23+ t .Fatalf ("expected: %v, got: %v" , tc .want , got )
24+ }
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments