Bitnot[w_]:=FromDigits[1-IntegerDigits[w,2,32],2]

Bitrotate[w_,n_]:=FromDigits[RotateLeft[IntegerDigits[w,2,32],n],2]

Pad[x_]:=
Block[{bits=Flatten[IntegerDigits[x,2,8]]},
Block[{len=Length[bits]},
AppendTo[bits,1];
AppendTo[bits,ConstantArray[0,Mod[448-(len+1),512]]];
AppendTo[bits,IntegerDigits[len,2,64]];
Map[FromDigits[#,2]&,Partition[Flatten[bits],8]]
]
]

input=ToCharacterCode["The quick brown fox jumps over the lazy dog"];

input//Map[{FromCharacterCode[#],#}&,#]&//Partition[#,8,8,{1,1},{}]&//TableForm

input//Map[{FromCharacterCode[#],#}&,#]&//Map[{#[[1]],IntegerString[#[[2]],16,2]}&,#]&//Partition[#,8,8,{1,1},{}]&//TableForm

input//Map[{FromCharacterCode[#],#}&,#]&//Map[{#[[1]],IntegerString[#[[2]],2,8]}&,#]&//Partition[#,8,8,{1,1},{}]&//TableForm

test=Pad[input];

test//Partition[#,8,8,{1,1},{}]&//IntegerString[#,2,8]&//TableForm

test//Partition[#,8,8,{1,1},{}]&//IntegerString[#,16,2]&//TableForm

IV=Map[FromDigits[#,16]&,{"67452301","EFCDAB89","98BADCFE","10325476","C3D2E1F0"}]

Block[{w=Map[FromDigits[#,256]&,Partition[test,4]]},
For[i=17,i≤80,i++,
AppendTo[w,
Bitrotate[
BitXor[w[[i-3]],w[[i-8]],w[[i-14]],w[[i-16]]],
1
]
];
];
w
]//IntegerString[#,16,8]&//Partition[#,8,8,{1,1},{}]&//TableForm

CompressionFunction[x_,h_]:=
Block[{w=Map[FromDigits[#,256]&,Partition[x,4]],result},
For[i=17,i≤80,i++,
AppendTo[w,
Bitrotate[
BitXor[w[[i-3]],w[[i-8]],w[[i-14]],w[[i-16]]],
1
]
];
];
Block[{a=h[[1]],b=h[[2]],c=h[[3]],d=h[[4]],e=h[[5]],f,k,temp},
For[i=1,i≤80,i++,
If[1≤i&&i≤20,
f=BitOr[BitAnd[b,c],BitAnd[Bitnot[b],d]];
k=FromDigits["5A827999",16];
];
If[21≤i&&i≤40,
f=BitXor[b,c,d];
k=FromDigits["6ED9EBA1",16];
];
If[41≤i&&i≤60,
f=BitOr[BitAnd[b,c],BitAnd[b,d],BitAnd[c,d]];
k=FromDigits["8F1BBCDC",16];
];
If[61≤i&&i≤80,
f=BitXor[b,c,d];
k=FromDigits["CA62C1D6",16];
];
temp=Mod[Bitrotate[a,5]+f+e+k+w[[i]],(2^32)];
e=d;
d=c;
c=Bitrotate[b,30];
b=a;
a=temp;
];
result=Mod[h+{a,b,c,d,e},(2^32)];
];
result
]

CompressionFunction[test,IV]

BaseForm[CompressionFunction[test,IV],16]

CompressionFunctionView[x_,h_,base_]:=
Block[{w=Map[FromDigits[#,256]&,Partition[x,4]],result,state={{"i","a","b","c","d","e","f","k","w","temp"}}},
For[i=17,i≤80,i++,
AppendTo[w,
Bitrotate[
BitXor[w[[i-3]],w[[i-8]],w[[i-14]],w[[i-16]]],
1
]
];
];
Block[{a=h[[1]],b=h[[2]],c=h[[3]],d=h[[4]],e=h[[5]],f=0,k,temp=0},
For[i=1,i≤80,i++,
AppendTo[state,Join[{i-1},IntegerString[{a,b,c,d,e,f,k,w[[i]],temp},base,32/Log[2,base]]]];
If[1≤i&&i≤20,
f=BitOr[BitAnd[b,c],BitAnd[Bitnot[b],d]];
k=FromDigits["5A827999",16];
];
If[21≤i&&i≤40,
f=BitXor[b,c,d];
k=FromDigits["6ED9EBA1",16];
];
If[41≤i&&i≤60,
f=BitOr[BitAnd[b,c],BitAnd[b,d],BitAnd[c,d]];
k=FromDigits["8F1BBCDC",16];
];
If[61≤i&&i≤80,
f=BitXor[b,c,d];
k=FromDigits["CA62C1D6",16];
];
temp=Mod[Bitrotate[a,5]+f+e+k+w[[i]],(2^32)];
e=d;
d=c;
c=Bitrotate[b,30];
b=a;
a=temp;
];
AppendTo[state,Join[{"final"},IntegerString[{a,b,c,d,e,f,k,w[[i-1]],temp},base,32/Log[2,base]]]];
AppendTo[state,{"i","a","b","c","d","e","f","k","w","temp"}];
result=Mod[h+{a,b,c,d,e},(2^32)];
AppendTo[state,Join[{"output"},IntegerString[result,base,32/Log[2,base]]]];
];
state
]

CompressionFunctionView[test,IV,16]//TableForm

SHA1[x_]:=Block[{h=IV,chunks=Partition[Pad[x],64],i},
Do[h=CompressionFunction[chunks[[i]],h],{i,Length[chunks]}];
IntegerString[FromDigits[h,(2^32)],16]
]

SHA1[input]

SHA1[Join[input,input]]

SHA1[ToCharacterCode["The quick brown fox jumps over the lazy cog"]]

SHA1[ToCharacterCode[""]]