SHA1 encoding to hex has 40 characters and 160 bits - encryption

An SHA1 digest should be 160 bits long. Still it is normally represented as a string with 40 characters. Considering 8-bits-bytes and that 1 char corresponds to 1 byte, it seems to me the SHA1 digest should have 20 bytes and it's hex representation 40 bytes.
For example, using OpenSSL I could get the following results (after manually removing extra information added):
PLAIN MESSAGE: The only possible revolution is inside us
openssl dgst -sha1 -hex dgsttxt &> sha1_hex
32 64 66 61 33 35 66 62 35 37 34 65 36 62 65 36 32 33 62 37 63 36 31 61 63 61 32 63 61 31 65 66 39 30 36 62 39 63 38 34
openssl dgst -sha1 -binary dgsttxt &> sha1_binary
2D FA 35 FB 57 4E 6B E6 23 B7 C6 1A CA 2C A1 EF 90 6B 9C 84
Applying a wc in each file I get
wc sha1_binary sha1_hex
0 1 20 sha1_binary
0 1 40 sha1_hex
0 2 60 total
So I have two questions:
Why are there 20 more characters in the hex dump?
How are those extra bits inserted? I could note each byte in the hex dump starts with either 3 or 6. Is there a particular reason for that?
I have already seen a similar question here but I am not sure if I am too stupid to understand the answers or if they are really poor. Any help is appreciated.

160 bits / 8 = 20 bytes; a byte in hex is 2 characters (00 to FF) and 2 * 20 = 40 hex characters.
The longer output is the hexadecimally encoded version of the hexadecimal encoded hash.
Quite what the point of that is, who knows.
var s = "32 64 66 61 33 35 66 62 35 37 34 65 36 62 65 36 32 33 62 37 63 36 31 61 63 61 32 63 61 31 65 66 39 30 36 62 39 63 38 34".split(" ");
for (var i = 0; i < s.length; i++)
{
document.write( String.fromCharCode(parseInt(s[i], 16)) );
}

Related

Problems with column labels after importing a csv file

I'm trying to import an anova data set csv file into R using the read.csv function. When I import it the columns are labelled X........ Even though the csv file the column labels are clearly person, gender etc
I don't know why this is. I've copied the code below. Any help would be appreciated
read.csv("/Users/Desktop/R /anova data set.csv")
X.......
1 ;Person;gender;Age;Height;pre.weight;Diet;weight6weeks
2 ;25; ;41;171;60;2;60
3 ;26; ;32;174;103;2;103
4 ;1;0;22;159;58;1;54.2
5 ;2;0;46;192;60;1;54
6 ;3;0;55;170;64;1;63.3
7 ;4;0;33;171;64;1;61.1
8 ;5;0;50;170;65;1;62.2
9 ;6;0;50;201;66;1;64
10 ;7;0;37;174;67;1;65
11 ;8;0;28;176;69;1;60.5
12 ;9;0;28;165;70;1;68.1
13 ;10;0;45;165;70;1;66.9
14 ;11;0;60;173;72;1;70.5
15 ;12;0;48;156;72;1;69
16 ;13;0;41;163;72;1;68.4
17 ;14;0;37;167;82;1;81.1
18 ;27;0;44;174;58;2;60.1
19 ;28;0;37;172;58;2;56
20 ;29;0;41;165;59;2;57.3
21 ;30;0;43;171;61;2;56.7
22 ;31;0;20;169;62;2;55
23 ;32;0;51;174;63;2;62.4
24 ;33;0;31;163;63;2;60.3
25 ;34;0;54;173;63;2;59.4
26 ;35;0;50;166;65;2;62
27 ;36;0;48;163;66;2;64
28 ;37;0;16;165;68;2;63.8
29 ;38;0;37;167;68;2;63.3
30 ;39;0;30;161;76;2;72.7
31 ;40;0;29;169;77;2;77.5
32 ;52;0;51;165;60;3;53
33 ;53;0;35;169;62;3;56.4
34 ;54;0;21;159;64;3;60.6
35 ;55;0;22;169;65;3;58.2
36 ;56;0;36;160;66;3;58.2
37 ;57;0;20;169;67;3;61.6
38 ;58;0;35;163;67;3;60.2
39 ;59;0;45;155;69;3;61.8
40 ;60;0;58;141;70;3;63
41 ;61;0;37;170;70;3;62.7
42 ;62;0;31;170;72;3;71.1
43 ;63;0;35;171;72;3;64.4
44 ;64;0;56;171;73;3;68.9
45 ;65;0;48;153;75;3;68.7
46 ;66;0;41;157;76;3;71
47 ;15;1;39;168;71;1;71.6
48 ;16;1;31;158;72;1;70.9
49 ;17;1;40;173;74;1;69.5
50 ;18;1;50;160;78;1;73.9
51 ;19;1;43;162;80;1;71
52 ;20;1;25;165;80;1;77.6
53 ;21;1;52;177;83;1;79.1
54 ;22;1;42;166;85;1;81.5
55 ;23;1;39;166;87;1;81.9
56 ;24;1;40;190;88;1;84.5
57 ;41;1;51;191;71;2;66.8
58 ;42;1;38;199;75;2;72.6
59 ;43;1;54;196;75;2;69.2
60 ;44;1;33;190;76;2;72.5
61 ;45;1;45;160;78;2;72.7
62 ;46;1;37;194;78;2;76.3
63 ;47;1;44;163;79;2;73.6
64 ;48;1;40;171;79;2;72.9
65 ;49;1;37;198;79;2;71.1
66 ;50;1;39;180;80;2;81.4
67 ;51;1;31;182;80;2;75.7
68 ;67;1;36;155;71;3;68.5
69 ;68;1;47;179;73;3;72.1
70 ;69;1;29;166;76;3;72.5
71 ;70;1;37;173;78;3;77.5
72 ;71;1;31;177;78;3;75.2
73 ;72;1;26;179;78;3;69.4
74 ;73;1;40;179;79;3;74.5
75 ;74;1;35;183;83;3;80.2
76 ;75;1;49;177;84;3;79.9
77 ;76;1;28;164;85;3;79.7
78 ;77;1;40;167;87;3;77.8
79 ;78;1;51;175;88;3;81.9
colnames(aov)
[1] "X......."

CSV File Histogram Generator : 'x' must be numeric

Basically, I'm trying to get a visualization of a histogram using R. My dataset has a column of data with the first row value "data" the remaining data are all numeric values the problem is when use the hist() function I am unable to visualize the data.
I've already looked over the solutions:
Solution 1
Solution 2
Solution 3
Solution 4
My Data Set:
V1
1 \357\273\277data
2 256
3 256
4 256
5 256
6 64
7 64
8 128
9 128
10 128
11 128
12 128
13 128
14 1024
15 1024
16 1024
17 1024
18 1024
19 1024
20 1024
21 1024
22 1024
23 1024
24 1024
25 1024
26 32
27 32
28 32
29 32
30 32
31 32
32 32
33 32
34 32
35 32
36 32
37 32
38 32
39 32
40 32
41 32
42 32
43 32
44 32
45 32
46 32
47 32
48 32
49 32
50 512
51 512
52 512
53 512
54 512
55 512
56 512
57 512
58 512
59 512
60 512
61 512
62 512
63 512
64 512
65 512
66 512
67 512
68 512
69 512
70 2
71 2
72 2
73 2
74 2
75 2
76 2
77 2
78 2
79 2
Code :
TD2 = read.csv("/Users/somename/Desktop/TD.csv",head=TRUE)
TD2 -- Result above
Also Tried :
data <- read.table("/Users/somename/Desktop/TD.csv", sep="\t")
TDR = read.csv("/Users/somename/Desktop/TD.csv",header = FALSE,sep = ",")
Result :
hist(TD2)
Error in hist.default(TD2) : 'x' must be numeric
hist(data)
Error in hist.default(data) : 'x' must be numeric
hist(TDR)
Error in hist.default(TDR) : 'x' must be numeric
You need to read the data with stringsAsFactors set to FALSE. Then the plot can be obtained as follows:
hist(as.numeric(df[-1,]))

Serial Measurement Data RS232 interpretation

I am trying to get readings from an ultrasonic thickness tester without using the included software, but I haven't been able to interpret the measurement readings from the tester.
Below are the hex values that are sent from the tester, and the corresponding decimal value that is displayed in the software.
3A 30 62 30 30 44 39 37 30 30 65 36 0D 0A 1.51
3A 30 62 30 30 44 66 61 30 30 34 39 0D 0A 2.50
3A 30 62 30 30 44 37 62 30 31 63 62 0D 0A 3.79
3A 30 62 30 30 44 38 32 30 31 64 32 0D 0A 3.86
3A 30 62 30 30 44 63 37 30 31 31 37 0D 0A 4.55
3A 30 62 30 30 44 39 34 30 62 65 65 0D 0A 29.64
3A 30 62 30 30 44 39 63 30 62 66 36 0D 0A 29.72
3A 30 62 30 30 44 63 61 30 62 32 34 0D 0A 30.18
3A 30 62 30 30 44 65 64 30 62 34 37 0D 0A 30.53
3A 30 62 30 30 44 38 65 33 65 31 62 0D 0A 160.14
3A 30 62 30 30 44 64 66 33 65 36 63 0D 0A 160.95
Any help on how I get from the hex values to the decimal value would be very much appreciated.
ASCII equivalent (I have omitted CR and LF which are at the end of each line) :
:0b00D9700e6 1.51
:0b00Dfa0049 2.50
:0b00D7b01cb 3.79
:0b00D8201d2 3.86
:0b00Dc70117 4.55
:0b00D940bee 29.64
:0b00D9c0bf6 29.72
:0b00Dca0b24 30.18
:0b00Ded0b47 30.53
:0b00D8e3e1b 160.14
:0b00Ddf3e6c 160.95
Finally figured it out:
The data is the two bytes after :0b00D, LSB first, multiplied by 100.
ASCII Hex Decimal
:0b00D9700e6 0097 1.51
:0b00Dfa0049 00fa 2.50
:0b00D7b01cb 017b 3.79
:0b00D8201d2 0182 3.86
:0b00Dc70117 01c7 4.55
:0b00D940bee 0b94 29.64
:0b00D9c0bf6 0b9c 29.72
:0b00Dca0b24 0bca 30.18
:0b00Ded0b47 0bed 30.53
:0b00D8e3e1b 3e8e 160.14
:0b00Ddf3e6c 3edf 160.95

Cumulative sum after 64 in R(Conditional Cumulative sum)

I am new to R. I am not sure how to do the following function in R. I am able to do this in excel. But not able to do it in R. Can anybody help me in this?
I want to get the cumulative sum of the counter value once it reaches 64,
The following is my data,
x
57
57
57
57
57
57
58
58
58
58
61
61
62
62
1
1
11
16
16
16
16
16
16
22
22
22
27
28
I want the cumulative sum after the count reaches 64. I am not sure how to do that in R.
The following is the output I require,
x
57
57
57
57
57
57
58
58
58
58
61
61
62
62
65
65
76
81
81
81
81
81
81
87
87
87
92
93
Can anybody help with doing this?
Thanks
If your data is resetting at 64, and continuing on, and you want it to keep the 64, try:
diffs <- c(dat$x[1], diff(dat$x))
diffs[diffs < 0] <- 64 + diffs[diffs < 0]
cumsum(diffs)
An explanation:
The first line takes all the differences from one number to the next, starting with the initial value (in the example case, 57).
The second line finds all negative diff values, and changes them to 64 + what they were - if it was 62 changing to 2, we need to add on 4: 2 to hit 64 and then 2 more.
The third line takes the cumsum to give the final values.

Finding files present in directory

An analysis which I ran produced around 500 files which are named file1 to file500
However, some files in between are missing (such as file233 and file245 as well as others). I would like to further process them in a loop in R but then I would need to filter out the files which are not present.
Is there an easy way to store the number after file in a vector in R which I can then use for the loop?
v<-containing all numbers after file which are present in the directory
Should have mentioned that the files do not have the ending .txt but are just names fileXX where the XX is the number
The best way is to simply create a list of the files that are actually present in the directory, like #beginneR said:
list_of_files = list.files('/path/to/dir')
do_some_processing = function(list_element) {
# Perform some processing and return something
}
lapply(list_of_files, do_some_processing)
If you need the numbers in the filename, a simple regular expression will do:
> grep('[0-9]', sprintf('file%d', 1:100))
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
[19] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
[37] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
[55] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
[73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
[91] 91 92 93 94 95 96 97 98 99 100

Resources