Last active
December 29, 2015 04:49
-
-
Save pasali/7617194 to your computer and use it in GitHub Desktop.
prog. dilleri ödev
This file contains hidden or 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 ( | |
"fmt" | |
"github.com/ActiveState/golor" | |
"math/rand" | |
"os" | |
"strconv" | |
"strings" | |
"time" | |
) | |
type PassCard struct { | |
chars []string | |
colors []int | |
id int64 | |
index int | |
symbols string | |
} | |
func (p *PassCard) setChars() { | |
switch p.index { | |
case 1: | |
p.chars = strings.Split("0123456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", "") | |
case 2: | |
p.chars = strings.Split("0123456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ@#$%&*<>?€+{}[]()/\\", "") | |
default: | |
p.chars = strings.Split("0123456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", "") | |
} | |
} | |
func (p *PassCard) setCardId() { | |
if len(os.Args) == 1 { | |
p.id = time.Now().UnixNano() | |
} else { | |
p.id, _ = strconv.ParseInt(os.Args[1], 16, 64) | |
} | |
} | |
func (p *PassCard) init() { | |
p.colors = []int{golor.CYAN, golor.RED, golor.BLACK, golor.YELLOW, golor.BLUE, | |
golor.MAGENTA, golor.GREEN, golor.GRAY} | |
p.symbols = "■□▲△○●★☂☀☁☹☺♠♣♥♦♫€¥£$!?¡¿⊙◐◩�" | |
p.setChars() | |
p.setCardId() | |
} | |
func (p *PassCard) shuffle() { | |
rand.Seed(p.id) | |
for i := range p.chars { | |
j := rand.Intn(i + 1) | |
p.chars[i], p.chars[j] = p.chars[j], p.chars[i] | |
} | |
} | |
func (p *PassCard) show() { | |
var k int | |
p.shuffle() | |
fmt.Println(" " + p.symbols) | |
for i := 0; i < 8; i++ { | |
fmt.Printf("%d ", i+1) | |
for k = 0; k < 29; k++ { | |
fmt.Print(golor.Colorize(p.chars[k], -1, p.colors[i])) | |
} | |
fmt.Print("\n") | |
p.shuffle() | |
} | |
} | |
func main() { | |
var p PassCard | |
fmt.Println("Karakter kümesini seçiniz: ") | |
fmt.Print(" 1 - Rakam + harflerden oluşan\n 2 - Tüm karakterleri içeren.\n") | |
fmt.Scanf("%d", &p.index) | |
p.init() | |
p.show() | |
fmt.Printf("Passwordcard id : %s\n", strconv.FormatInt(p.id, 16)) | |
} |
Değerlendirmeni dikkate alacağım sayın austa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bence p.init() ve p.show() fonksiyonlarını main() içerisinde çalıştırmalısın.