Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
50
Task/SHA-1/NetRexx/sha-1.netrexx
Normal file
50
Task/SHA-1/NetRexx/sha-1.netrexx
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref savelog symbols binary
|
||||
|
||||
import java.security.MessageDigest
|
||||
|
||||
SHA1('Rosetta Code', '48c98f7e5a6e736d790ab740dfc3f51a61abe2b5')
|
||||
|
||||
return
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method SHA1(messageText, verifyCheck) public static
|
||||
|
||||
algorithm = 'SHA-1'
|
||||
digestSum = getDigest(messageText, algorithm)
|
||||
|
||||
say '<Message>'messageText'</Message>'
|
||||
say Rexx('<'algorithm'>').right(12) || digestSum'</'algorithm'>'
|
||||
say Rexx('<Verify>').right(12) || verifyCheck'</Verify>'
|
||||
if digestSum == verifyCheck then say algorithm 'Confirmed'
|
||||
else say algorithm 'Failed'
|
||||
|
||||
return
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method getDigest(messageText = Rexx, algorithm = Rexx 'MD5', encoding = Rexx 'UTF-8', lowercase = boolean 1) public static returns Rexx
|
||||
|
||||
algorithm = algorithm.upper
|
||||
encoding = encoding.upper
|
||||
|
||||
message = String(messageText)
|
||||
messageBytes = byte[]
|
||||
digestBytes = byte[]
|
||||
digestSum = Rexx ''
|
||||
|
||||
do
|
||||
messageBytes = message.getBytes(encoding)
|
||||
md = MessageDigest.getInstance(algorithm)
|
||||
md.update(messageBytes)
|
||||
digestBytes = md.digest
|
||||
|
||||
loop b_ = 0 to digestBytes.length - 1
|
||||
bb = Rexx(digestBytes[b_]).d2x(2)
|
||||
if lowercase then digestSum = digestSum || bb.lower
|
||||
else digestSum = digestSum || bb.upper
|
||||
end b_
|
||||
catch ex = Exception
|
||||
ex.printStackTrace
|
||||
end
|
||||
|
||||
return digestSum
|
||||
Loading…
Add table
Add a link
Reference in a new issue