when I connect to a ssh in powershell
I got such strings
?]0;wany#wany02: ~?[01;32mwany#wany02?[00m:?[01;34m~?[00m$
I print the bytes of the string
[27 93 48 59 119 97 110 121 64 119 97 110 121 48 50 58 32 126 7 27 91 48 49 59 51 50 109 119 97 110 121 64 119 97 110 121 48 50 27 91 48 48 109 58 27 91 48 49 59 51 52 109 126 27 91 48 48 109 36 32]
I've used the [ansicolor]: https://github.com/shiena/ansicolor package to convert color
but,what the meaning of "?]0;wany#wany02: ~?"
I can't see it on Linux terminal
thx a lot
ESC]0; is the start of an escape code that xterm and compatible terminals that implement VT100 control sequences use to change the window's title and icon name. The byte with the value 7 (ASCII BEL) ends the sequence. Everything between is used as the title.
Using 2 instead of 0 changes just the title and 1 just the icon name. See the list of operating system controls for what other numbers do.
Related
I read geojson with
json, err := ioutil.ReadFile(file)
Then I Print result and see this
[123 32 34 116 121 112 101 34 58 32 34 70 101 97 116 117 114 101 67
111 108 108 101 99 116 105 111 110 34 44 10 32 32 32 32 34 102 101 97
116 117 114 101 115 34 58 32 91 10 32 32 32 32 32 32 123 32 34 116 121
112 101 34 58 32 34 70 101 97 116 117 114 101 34 44 10 32 32 32 32 32
32 32 32 34 103 101 111 109 101 116 114 121 34 58 32 123 34 116 121
112 101 34 58 32 34 80 111 105 110 116 34 44 32 34 99 111 111 114 100
105 110 97 116 101 115 34 58 32 91 49 48 50 46 48 44 32 48 46 53 93
125 44 10 32 32 32 32 32 32 32 32 34 112 114 111 112 101 114 116 105
101 115 34 58 32 123 34 112 114 111 112 48 34 58 32 34 118 97 108 117
101 48 34 125 10 32 32 32 32 32 32 32 32 125 44 10 32 32 32 32 32 32
123 32 34 116 121 112 101 34 58 32 34 70 101 97 116 117 114 101 34 44
10 32 32 32 32 32 32 32 32 34 103 101 111 109 101 116 114 121 34 58 32
123 10 32 32 32 32 32 32 32 32 32 32 34 116 121 112 101 34 58 32 34 76
105 110 101 83 116 114 105 110 103 34 44 10 32 32 32 32 32 32 32 32 32
32 34 99 111 111 114 100 105 110 97 116 101 115 34 58 32 91 10 32 32
32 32 32 32 32 32 32 32 32 32 91 49 48 50 46 48 44 32 48 46 48 93 44
32 91 49 48 51 46 48 44 32 49 46 48 93 44 32 91 49 48 52 46 48 44 32
48 46 48 93 44 32 91 49 48 53 46 48 44 32 49 46 48 93 10 32 32 32 32
32 32 32 32 32 32 32 32 93 10 32 32 32 32 32 32 32 32 32 32 125 44 10
32 32 32 32 32 32 32 32 34 112 114 111 112 101 114 116 105 101 115 34
58 32 123 10 32 32 32 32 32 32 32 32 32 32 34 112 114 111 112 48 34 58
32 34 118 97 108 117 101 48 34 44 10 32 32 32 32 32 32 32 32 32 32 34
112 114 111 112 49 34 58 32 48 46 48 10 32 32 32 32 32 32 32 32 32 32
125 10 32 32 32 32 32 32 32 32 125 44 10 32 32 32 32 32 32 123 32 34
116 121 112 101 34 58 32 34 70 101 97 116 117 114 101 34 44 10 32 32
32 32 32 32 32 32 32 34 103 101 111 109 101 116 114 121 34 58 32 123
10 32 32 32 32 32 32 32 32 32 32 32 34 116 121 112 101 34 58 32 34 80
111 108 121 103 111 110 34 44 10 32 32 32 32 32 32 32 32 32 32 32 34
99 111 111 114 100 105 110 97 116 101 115 34 58 32 91 10 32 32 32 32
32 32 32 32 32 32 32 32 32 91 32 91 49 48 48 46 48 44 32 48 46 48 93
44 32 91 49 48 49 46 48 44 32 48 46 48 93 44 32 91 49 48 49 46 48 44
32 49 46 48 93 44 10 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 91
49 48 48 46 48 44 32 49 46 48 93 44 32 91 49 48 48 46 48 44 32 48 46
48 93 32 93 10 32 32 32 32 32 32 32 32 32 32 32 32 32 93 10 32 32 32
32 32 32 32 32 32 125 44 10 32 32 32 32 32 32 32 32 32 34 112 114 111
112 101 114 116 105 101 115 34 58 32 123 10 32 32 32 32 32 32 32 32 32
32 32 34 112 114 111 112 48 34 58 32 34 118 97 108 117 101 48 34 44 10
32 32 32 32 32 32 32 32 32 32 32 34 112 114 111 112 49 34 58 32 123 34
116 104 105 115 34 58 32 34 116 104 97 116 34 125 10 32 32 32 32 32 32
32 32 32 32 32 125 10 32 32 32 32 32 32 32 32 32 125 10 32 32 32 32 32
32 32 93 10 32 32 32 32 32 125]
After than I Unmarshal it and print again and I got this
{FeatureCollection [{Feature map[prop0:value0] {Point [102
0.5]}} {Feature map[prop0:value0 prop1:0] {LineString [[102 0] [103 1] [104 0] [105 1]]}} {Feature map[prop0:value0 prop1:map[this:that]]
{Polygon [[[100 0] [101 0] [101 1] [100 1] [100 0]]]}}]}
Than I Marshal it and got this
[123 34 116 121 112 101 34 58 34 70 101 97 116 117 114 101 67 111 108
108 101 99 116 105 111 110 34 44 34 102 101 97 116 117 114 101 115 34
58 91 123 34 116 121 112 101 34 58 34 70 101 97 116 117 114 101 34 44
34 112 114 111 112 101 114 116 105 101 115 34 58 123 34 112 114 111
112 48 34 58 34 118 97 108 117 101 48 34 125 44 34 103 101 111 109 101
116 114 121 34 58 123 34 116 121 112 101 34 58 34 80 111 105 110 116
34 44 34 99 111 111 114 100 105 110 97 116 101 115 34 58 91 49 48 50
44 48 46 53 93 125 125 44 123 34 116 121 112 101 34 58 34 70 101 97
116 117 114 101 34 44 34 112 114 111 112 101 114 116 105 101 115 34 58
123 34 112 114 111 112 48 34 58 34 118 97 108 117 101 48 34 44 34 112
114 111 112 49 34 58 48 125 44 34 103 101 111 109 101 116 114 121 34
58 123 34 116 121 112 101 34 58 34 76 105 110 101 83 116 114 105 110
103 34 44 34 99 111 111 114 100 105 110 97 116 101 115 34 58 91 91 49
48 50 44 48 93 44 91 49 48 51 44 49 93 44 91 49 48 52 44 48 93 44 91
49 48 53 44 49 93 93 125 125 44 123 34 116 121 112 101 34 58 34 70 101
97 116 117 114 101 34 44 34 112 114 111 112 101 114 116 105 101 115 34
58 123 34 112 114 111 112 48 34 58 34 118 97 108 117 101 48 34 44 34
112 114 111 112 49 34 58 123 34 116 104 105 115 34 58 34 116 104 97
116 34 125 125 44 34 103 101 111 109 101 116 114 121 34 58 123 34 116
121 112 101 34 58 34 80 111 108 121 103 111 110 34 44 34 99 111 111
114 100 105 110 97 116 101 115 34 58 91 91 91 49 48 48 44 48 93 44 91
49 48 49 44 48 93 44 91 49 48 49 44 49 93 44 91 49 48 48 44 49 93 44
91 49 48 48 44 48 93 93 93 125 125 93 125]
After Unmarshalling I got the same
{FeatureCollection [{Feature map[prop0:value0] {Point [102 0.5]}}
{Feature map[prop0:value0 prop1:0] {LineString [[102 0] [103 1] [104
0] [105 1]]}} {Feature map[prop0:value0 prop1:map[this:that]] {Polygon
[[[100 0] [101 0] [101 1] [100 1] [100 0]]]}}]}
Why is that so? Why do I have different number of bytes and why after Unmarshalling these different bytes I got the same result?
The original file contains many spaces and new-lines, you can see them in your output (32 = Space). json.Unmarshal() will remove all those spaces and json.Marshal() won't add them again. If you want to pretty format your second output you can use json.MarshalIndent().
I am using Bcrypt in Go to hash and compare the password given by the user. The thing is in the login, when I compare the password using CompareHashAndPassword it never matches so always says that the password is incorrect. Based on the concept of hash is supposed that with the same input we will have anytime the same output, and this is not my case.
**My code to hash (in the sign up) **
bs, err := bcrypt.GenerateFromPassword([]byte(Password), bcrypt.MinCost)
What I did
Send as password: 12345
When I print bs I get:
Attempt 1: [36 50 97 36 48 52 36 49 104 78 117 77 56 73 113 99 114 78 99 111 100 57 57 120 101 69 117 118 117 103 87 108 68 76 88 70 119 110 65 116 68 108 118
57 68 86 81 88 77 50 71 78 101 81 104 65 54 67 107 121]
Attempt 2:
[36 50 97 36 48 52 36 47 50 84 70 73 120 56 70 67 116 69 101 48 113 86 89 103 89 119 71 97 46 120 77 116 83 86 57 56 112 122 66 103 46 106 74 104 10
8 82 113 117 85 110 51 103 115 107 109 102 109 49 115 113]
Attempt 3:
[36 50 97 36 48 52 36 51 103 97 117 103 49 74 110 113 85 101 113 54 121 69 108 109 72 76 108 72 46 85 121 65 87 122 103 119 88 71 82 114 56 105 65 6
9 49 113 73 112 52 48 85 69 85 47 118 56 56 47 48 67]
Correct me if I am wrong, but in all that attempts the result should not be the same?
Then, I save that values in the database and these are the values for each attempt:
$2a$04$1hNuM8IqcrNcod99xeEuvugWlDLXFwnAtDlv9DVQXM2GNeQhA6Cky
$2a$04$/2TFIx8FCtEe0qVYgYwGa.xMtSV98pzBg.jJhlRquUn3gskmfm1sq
$2a$04$3gaug1JnqUeq6yElmHLlH.UyAWzgwXGRr8iAE1qIp40UEU/v88/0C
Then, to compare the password, in the login:
err := bcrypt.CompareHashAndPassword(user.Password, []byte(p))
user.Password is a []byte this value is conusulted from the database
Thank you
p is the password send in the form by the user
Bcrypt generates a random salt (that is included as a part of the resulting hash). So it is different every time with purpose.
You need to use bcrypt.CompareHashAndPassword to compare the hashed password and the plaintext password.
The first argument of bcrypt.CompareHashAndPassword is the hashed password, the second is the plaintext password. So you passed them in the wrong order.
WARNING: the cost you've chosen 4 is extremely low. Consider choosing something like 10 or over.
I am using the Golang Bcrypt algorithm and it returns in bytes for instance
password := []byte("MyPassword")
hashedPassword, err := bcrypt.GenerateFromPassword(password, 12)
That code above returns a hashPassword of
[36 50 97 36 49 50 36 103 118 90 90 104 82 114 99 88 113 81 46 48 69 52 105 51 82 71 53 104 101 83 79 107 80 110 53 103 53 99 84 110 97 99 82 106 56 68 66 54 84 89 83 107 100 108 87 67 115 57 77 97]
My question is; is that as save as the string implementation that I've used in Java and C# where the Hashpassword would be return in strings,numerals and other characters ? I have got the code and testing it from https://godoc.org/golang.org/x/crypto/bcrypt#CompareHashAndPassword .
Yes, bcrypt's functions do operate on byte slices, however, the returned hash is base64 encoded. A string representation of the hashed password can therefore be obtained by doing a string conversion:
hashedPasswordStr := string(hashedPassword)
This question provides some reasons why arrays are preferred for storing passwords over strings (different language, but same principles).
My PPM image contains the following :
P6
1200
670
255
ܒNԪjɝ[؋Cц:̈6y5"r-¼,ֈ?Ԛ_݈̻֬كڕÒɪxڇՄmxɘl܊؇euί\jĩqÿHqAʻKPùG9EʁM͂MO̿PɼLȀMǃOǁLƾH»D5A®>ǷFxCٲ;yFƾIǿJʀL»GڲAʂWǯŐĕх՜џᔡ嚪矱Ԫׄ࠘ĝцQfһψ΅e{ڈڗÖܻԡȜׂӐ}˸_hؖ`u؛dьWЋV̓MͺHυPƽF˂I>ٹ6}>س5>Eiuƻ1
and 40000 more lines of illegible code. Is this an encoding issue?
If you want it in ASCII P3 format, you can use ImageMagick, which is in most Linux distros and available for OSX and Windows,iike this
convert yourFile.ppm -compress none output.ppm
Then it will look like this:
P3
70 46
255
48 47 45 50 48 46 54 50 47 56 51 46 58 51 45 57 50 45 56 48 45 57 49 46
56 48 45 56 48 45 55 47 44 53 45 42 52 44 41 53 45 42 53 45 42 49 45 39
49 46 39 52 49 42 55 52 45 57 54 47 63 58 47 70 63 51 74 66 52 76 65 50
...
...
No, this is completely normal for a mode P6 PPM.
In this mode, only the header is ASCII, the pixels are written as binary data, 8 or 16 bits per sample, pixel interleaved.
It's also possible to have PPM in "plain" or ASCII format, this mode uses P3 as its identifier.
See the PPM spec for more info.
I am a beginner in Golang. I wrote a function that will take variable args and pass it to another function that accepts variable args. I used "exec.Command()" for the second one. Here is my program
package main
import "fmt"
import "os/exec"
func execute(command string, parameters ...string) {
cmd := exec.Command(command, parameters...)
fmt.Println("Path =", cmd.Path, "Args =", cmd.Args, "Dir =", cmd.Dir)
out,_ := cmd.Output()
fmt.Println("Output =", out)
}
func main() {
execute("ls", "-l")
}
I expected it to return the list of files in the current directory. Instead I get a strange result
# go build command.go
#./command
Path = /bin/ls Args = [ls -l] Dir =
Output = [116 111 116 97 108 32 57 49 52 52 10 45 114 119 120 114 45 120 114 45 120 32 49 32 114 111 111 116 32 114 111 111 116 32 50 55 53 55 57 53 50 32 78 111 118 32 50 48 32 49 55 58 50 54 32 99 111 109 109 97 110 100 10 45 114 119 45 114 45 45 114 45 45 32 49 32 114 111 111 116 32 114 111 111 116 32 32 32 32 32 51 48 55 32 78 111 118 32 50 48 32 49 55 58 50 54 32 99 111 109 109 97 110 100 46 103 111 10 45 114 119 120 114 45 120 114 45 120 32 49 32 114 111 111 116 32 114 111 111 116 32 51 52 48 49 48 51 50 32 78 111 118 32 50 48 32 49 53 58 52 51 32 110 101 120 117 115 49 48 48 48 118 10 45 114 119 45 114 45 45 114 45 45 32 49 32 114 111 111 116 32 114 111 111 116 32 32 32 32 56 57 48 52 32 78 111 118 32 50 48 32 49 53 58 52 51 32 110 101 120 117 115 49 48 48 48 118 46 103 111 10 45 114 119 120 114 45 120 114 45 120 32 49 32 114 111 111 116 32 114 111 111 116 32 51 49 55 53 52 48 48 32 78 111 118 32 50 48 32 49 55 58 50 52 32 116 101 115 116 110 101 116 10 45 114 119 45 114 45 45 114 45 45 32 49 32 114 111 111 116 32 114 111 111 116 32 32 32 32 32 52 55 56 32 78 111 118 32 50 48 32 49 55 58 50 53 32 116 101 115 116 110 101 116 46 103 111 10]
What am I doing wrong
You are printing a byte slice.
fmt.Println("Output =", out)
Convert it to a string.
fmt.Println("Output =", string(out))
When using the fmt package, the formatting string is very concise:
fmt.Printf("%s\n", out)