fix coin flip
This commit is contained in:
		
							
								
								
									
										14
									
								
								password.go
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								password.go
									
									
									
									
									
								
							@@ -3,26 +3,20 @@ package scsusers
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"crypto/rand"
 | 
						"crypto/rand"
 | 
				
			||||||
	"encoding/base32"
 | 
						"encoding/base32"
 | 
				
			||||||
 | 
						mr "math/rand"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
	"unicode"
 | 
						"unicode"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func flipCoin() bool {
 | 
					func flipCoin() bool {
 | 
				
			||||||
	x := make([]byte, 1)
 | 
						r:=mr.New(mr.NewSource(time.Now().Unix()))
 | 
				
			||||||
	_, err := rand.Read(x)
 | 
						return r.Intn(2)==1
 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return true
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if uint8(x[0]) % 2==0 {
 | 
					 | 
				
			||||||
		return true
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return false
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
func scrambleCase(in []byte) []byte {
 | 
					func scrambleCase(in []byte) []byte {
 | 
				
			||||||
	var out []byte
 | 
						var out []byte
 | 
				
			||||||
	for _, x := range string(in) {
 | 
						for _, x := range string(in) {
 | 
				
			||||||
		if unicode.IsUpper(x) {
 | 
							if unicode.IsUpper(x) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
			if flipCoin() {
 | 
								if flipCoin() {
 | 
				
			||||||
				out = append(out, byte(x))
 | 
									out = append(out, byte(x))
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user