1319
@c -----------------------------------------------------------------------------
1320
@node Octets and Utilities for Cryptography, , String Processing, stringproc
1321
@section Octets and Utilities for Cryptography
1323
@c -----------------------------------------------------------------------------
1325
@deffn {Function} base64 (@var{arg})
1327
Returns the base64-representation of @var{arg} as a string.
1328
The argument @var{arg} may be a string, a non-negative integer or a list of octets.
1333
(%i1) base64: base64("foo bar baz");
1334
(%o1) Zm9vIGJhciBiYXo=
1335
(%i2) string: base64_decode(base64);
1338
(%i4) integer: base64_decode(base64, 'number);
1339
(%o4) 666f6f206261722062617a
1340
(%i5) octets: base64_decode(base64, 'list);
1341
(%o5) [66, 6F, 6F, 20, 62, 61, 72, 20, 62, 61, 7A]
1343
(%i7) base64(octets);
1344
(%o7) Zm9vIGJhciBiYXo=
1347
Note that if @var{arg} contains umlauts (resp. octets larger than 127)
1348
the resulting base64-string is platform dependend.
1349
However the decoded string will be equal to the original.
1352
@category{Package stringproc}
1357
@c -----------------------------------------------------------------------------
1358
@anchor{base64_decode}
1359
@deffn {Function} base64_decode @
1360
@fname{base64_decode} (@var{base64-string}) @
1361
@fname{base64_decode} (@var{base64-string}, @var{return-type})
1363
By default @code{base64_decode} decodes the @var{base64-string} back to the original string.
1365
The optional argument @var{return-type} allows @code{base64_decode} to
1366
alternatively return the corresponding number or list of octets.
1368
Example: See @ref{base64}.
1371
@category{Package stringproc}
1376
@c -----------------------------------------------------------------------------
1378
@deffn {Function} crc24sum @
1379
@fname{crc24sum} (@var{octets}) @
1380
@fname{crc24sum} (@var{octets}, @var{return-type})
1382
By default @code{crc24sum} returns the @code{CRC24} checksum of an octet-list
1385
The optional argument @var{return-type} allows @code{crc24sum} to
1386
alternatively return the corresponding number or list of octets.
1390
-----BEGIN PGP SIGNATURE-----
1391
Version: GnuPG v2.0.22 (GNU/Linux)
1393
iQEcBAEBAgAGBQJVdCTzAAoJEG/1Mgf2DWAqCSYH/AhVFwhu1D89C3/QFcgVvZTM
1394
wnOYzBUURJAL/cT+IngkLEpp3hEbREcugWp+Tm6aw3R4CdJ7G3FLxExBH/5KnDHi
1395
rBQu+I7+3ySK2hpryQ6Wx5J9uZSa4YmfsNteR8up0zGkaulJeWkS4pjiRM+auWVe
1396
vajlKZCIK52P080DG7Q2dpshh4fgTeNwqCuCiBhQ73t8g1IaLdhDN6EzJVjGIzam
1397
/spqT/sTo6sw8yDOJjvU+Qvn6/mSMjC/YxjhRMaQt9EMrR1AZ4ukBF5uG1S7mXOH
1398
WdiwkSPZ3gnIBhM9SuC076gLWZUNs6NqTeE3UzMjDAFhH3jYk1T7mysCvdtIkms=
1400
-----END PGP SIGNATURE-----
1404
(%i1) ibase : obase : 16.$
1405
(%i2) sig64 : sconcat(
1406
"iQEcBAEBAgAGBQJVdCTzAAoJEG/1Mgf2DWAqCSYH/AhVFwhu1D89C3/QFcgVvZTM",
1407
"wnOYzBUURJAL/cT+IngkLEpp3hEbREcugWp+Tm6aw3R4CdJ7G3FLxExBH/5KnDHi",
1408
"rBQu+I7+3ySK2hpryQ6Wx5J9uZSa4YmfsNteR8up0zGkaulJeWkS4pjiRM+auWVe",
1409
"vajlKZCIK52P080DG7Q2dpshh4fgTeNwqCuCiBhQ73t8g1IaLdhDN6EzJVjGIzam",
1410
"/spqT/sTo6sw8yDOJjvU+Qvn6/mSMjC/YxjhRMaQt9EMrR1AZ4ukBF5uG1S7mXOH",
1411
"WdiwkSPZ3gnIBhM9SuC076gLWZUNs6NqTeE3UzMjDAFhH3jYk1T7mysCvdtIkms=" )$
1412
(%i3) octets: base64_decode(sig64, 'list)$
1413
(%i4) crc24: crc24sum(octets, 'list);
1415
(%i5) base64(crc24);
1420
@category{Package stringproc}
1425
@c -----------------------------------------------------------------------------
1427
@deffn {Function} md5sum @
1428
@fname{md5sum} (@var{arg}) @
1429
@fname{md5sum} (@var{arg}, @var{return-type})
1431
Returns the @code{MD5} checksum of a string, a non-negative integer or
1432
a list of octets. The default return value is a string containing 32 hex characters.
1434
The optional argument @var{return-type} allows @code{md5sum} to alternatively
1435
return the corresponding number or list of octets.
1440
(%i1) ibase: obase: 16.$
1441
(%i2) msg: "foo bar baz"$
1442
(%i3) string: md5sum(msg);
1443
(%o3) ab07acbb1e496801937adfa772424bf7
1444
(%i4) integer: md5sum(msg, 'number);
1445
(%o4) 0ab07acbb1e496801937adfa772424bf7
1446
(%i5) octets: md5sum(msg, 'list);
1447
(%o5) [0AB,7,0AC,0BB,1E,49,68,1,93,7A,0DF,0A7,72,42,4B,0F7]
1448
(%i6) sdowncase( printf(false, "~@{~2,'0x~^:~@}", octets) );
1449
(%o6) ab:07:ac:bb:1e:49:68:01:93:7a:df:a7:72:42:4b:f7
1452
Note that in case @var{arg} contains German umlauts or other non-ASCII
1453
characters (resp. octets larger than 127) the @code{MD5} checksum is platform dependend.
1456
@category{Package stringproc}
1461
@c -----------------------------------------------------------------------------
1462
@anchor{number_to_octets}
1463
@deffn {Function} number_to_octets (@var{number})
1465
Returns an octet-representation of @var{number} as a list of octets.
1466
The @var{number} must be a non-negative integer.
1471
(%i1) ibase : obase : 16.$
1472
(%i2) octets: [0ca,0fe,0ba,0be]$
1473
(%i3) number: octets_to_number(octets);
1475
(%i4) number_to_octets(number);
1476
(%o4) [0CA, 0FE, 0BA, 0BE]
1480
@category{Package stringproc}
1485
@c -----------------------------------------------------------------------------
1486
@anchor{octets_to_number}
1487
@deffn {Function} octets_to_number (@var{octets})
1489
Returns a number by concatenating the octets in the list of @var{octets}.
1491
Example: See @ref{number_to_octets}.
1494
@category{Package stringproc}
1499
@c -----------------------------------------------------------------------------
1500
@anchor{octets_to_oid}
1501
@deffn {Function} octets_to_oid (@var{octets})
1503
Computes an object identifier (OID) from the list of @var{octets}.
1505
Example: RSA encryption OID
1508
(%i1) ibase : obase : 16.$
1509
(%i2) oid: octets_to_oid([2A,86,48,86,0F7,0D,1,1,1]);
1510
(%o2) 1.2.840.113549.1.1.1
1511
(%i3) oid_to_octets(oid);
1512
(%o3) [2A, 86, 48, 86, 0F7, 0D, 1, 1, 1]
1516
@category{Package stringproc}
1521
@c -----------------------------------------------------------------------------
1522
@anchor{oid_to_octets}
1523
@deffn {Function} oid_to_octets (@var{oid-string})
1525
Convertes an object identifier (OID) to a list of @var{octets}.
1527
Example: See @ref{octets_to_oid}.
1530
@category{Package stringproc}
1535
@c -----------------------------------------------------------------------------
1537
@deffn {Function} sha1sum @
1538
@fname{sha1sum} (@var{arg}) @
1539
@fname{sha1sum} (@var{arg}, @var{return-type})
1541
Returns the @code{SHA1} fingerprint of a string, a non-negative integer or
1542
a list of octets. The default return value is a string containing 40 hex characters.
1544
The optional argument @var{return-type} allows @code{sha1sum} to alternatively
1545
return the corresponding number or list of octets.
1550
(%i1) ibase: obase: 16.$
1551
(%i2) msg: "foo bar baz"$
1552
(%i3) string: sha1sum(msg);
1553
(%o3) c7567e8b39e2428e38bf9c9226ac68de4c67dc39
1554
(%i4) integer: sha1sum(msg, 'number);
1555
(%o4) 0c7567e8b39e2428e38bf9c9226ac68de4c67dc39
1556
(%i5) octets: sha1sum(msg, 'list);
1557
(%o5) [0C7,56,7E,8B,39,0E2,42,8E,38,0BF,9C,92,26,0AC,68,0DE,4C,67,0DC,39]
1558
(%i6) sdowncase( printf(false, "~@{~2,'0x~^:~@}", octets) );
1559
(%o6) c7:56:7e:8b:39:e2:42:8e:38:bf:9c:92:26:ac:68:de:4c:67:dc:39
1562
Note that in case @var{arg} contains German umlauts or other non-ASCII
1563
characters (resp. octets larger than 127) the @code{SHA1} fingerprint is platform dependend.
1566
@category{Package stringproc}
1571
@c -----------------------------------------------------------------------------
1573
@deffn {Function} sha256sum @
1574
@fname{sha256sum} (@var{arg}) @
1575
@fname{sha256sum} (@var{arg}, @var{return-type})
1577
Returns the @code{SHA256} fingerprint of a string, a non-negative integer or
1578
a list of octets. The default return value is a string containing 64 hex characters.
1580
The optional argument @var{return-type} allows @code{sha256sum} to alternatively
1581
return the corresponding number or list of octets (see @ref{sha1sum}).
1586
(%i1) string: sha256sum("foo bar baz");
1587
(%o1) dbd318c1c462aee872f41109a4dfd3048871a03dedd0fe0e757ced57dad6f2d7
1590
Note that in case @var{arg} contains German umlauts or other non-ASCII
1591
characters (resp. octets larger than 127) the @code{SHA256} fingerprint is platform dependend.
1594
@category{Package stringproc}