Skip to content

Instantly share code, notes, and snippets.

@pasali
Last active December 29, 2015 04:49
Show Gist options
  • Save pasali/7617194 to your computer and use it in GitHub Desktop.
Save pasali/7617194 to your computer and use it in GitHub Desktop.
prog. dilleri ödev
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))
}
@austa
Copy link

austa commented Nov 26, 2013

Bence p.init() ve p.show() fonksiyonlarını main() içerisinde çalıştırmalısın.

@pasali
Copy link
Author

pasali commented Nov 26, 2013

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