Last active
November 23, 2019 08:17
-
-
Save u1aryz/f7fb7d28a994c2d2db228d61fddf51dd to your computer and use it in GitHub Desktop.
Print dot alias all pattern of gmail(G Suite).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"math" | |
"os" | |
"strings" | |
) | |
var ( | |
email = flag.String("email", "", "Set email") | |
) | |
func main() { | |
flag.Parse() | |
if len(*email) == 0 { | |
// Require --email option | |
fmt.Println("Error: args <email> is required.") | |
os.Exit(1) | |
} | |
// Split into username and domain | |
split := strings.Split(*email, "@") | |
user := split[0] | |
user = strings.Replace(user, ".", "", -1) | |
domain := "" | |
if len(split) > 1 { | |
// Domain exists | |
domain = split[1] | |
} | |
n := len(user) - 1 | |
// Number of patterns | |
patternCnt := int(math.Pow(2, float64(n))) | |
for i := 0; i < patternCnt; i++ { | |
alias := "" | |
for j, v := range user { | |
alias += string(v) | |
if (i >> j & 1) == 1 { | |
alias += "." | |
} | |
} | |
if len(domain) > 0 { | |
// Put domain if exists | |
alias += "@" + domain | |
} | |
fmt.Println(alias) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment