~gabriel1984sibiu/maxima/trunk

« back to all changes in this revision

Viewing changes to doc/info/stringproc.texi

  • Committer: Robert Dodier
  • Date: 2015-06-25 06:26:32 UTC
  • mfrom: (9872.1.5)
  • Revision ID: git-v1:d4e25ec767689b44ea8386a7bbff512b57120704
Merge branch 'master' of ssh://git.code.sf.net/p/maxima/code

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
@menu
2
 
* Introduction to string processing::
3
 
* Functions and Variables for input and output::
4
 
* Functions and Variables for characters::
5
 
* Functions and Variables for strings::
 
2
* Introduction to String Processing::
 
3
* Input and Output::
 
4
* Characters::
 
5
* String Processing::
 
6
* Octets and Utilities for Cryptography::
6
7
@end menu
7
8
 
8
 
@node Introduction to string processing, Functions and Variables for input and output, stringproc, stringproc
9
 
@section Introduction to string processing
 
9
@node Introduction to String Processing, Input and Output, stringproc, stringproc
 
10
@section Introduction to String Processing
10
11
 
11
12
@code{stringproc.lisp} enlarges Maximas capabilities of working with strings 
12
13
and adds some useful functions for file in/output.
112
113
@closecatbox
113
114
 
114
115
 
115
 
@node Functions and Variables for input and output, Functions and Variables for characters, Introduction to string processing, stringproc
116
 
@section Functions and Variables for input and output
 
116
@node Input and Output, Characters, Introduction to String Processing, stringproc
 
117
@section Input and Output
117
118
 
118
119
Example: 
119
120
 
507
508
@closecatbox
508
509
@end deffn
509
510
 
510
 
@node Functions and Variables for characters, Functions and Variables for strings, Functions and Variables for input and output, stringproc
511
 
@section Functions and Variables for characters
 
511
@node Characters, String Processing, Input and Output, stringproc
 
512
@section Characters
512
513
 
513
514
@deffn {Function} alphacharp (@var{char})    
514
515
Returns @code{true} if @var{char} is an alphabetic character. 
722
723
@end deffn
723
724
 
724
725
@c -----------------------------------------------------------------------------
725
 
@node Functions and Variables for strings,  , Functions and Variables for characters, stringproc
726
 
@section Functions and Variables for strings
727
 
 
728
 
@c -----------------------------------------------------------------------------
729
 
@anchor{base64}
730
 
@deffn {Function} base64 (@var{string})
731
 
 
732
 
Returns the base64-representation of @var{string} as a string.
733
 
 
734
 
Example:
735
 
 
736
 
@example
737
 
(%i1) base64 : base64("foo bar baz");
738
 
(%o1)                       Zm9vIGJhciBiYXo=
739
 
(%i2) string : base64_decode(base64);
740
 
(%o2)                          foo bar baz
741
 
@end example
742
 
 
743
 
@opencatbox
744
 
@category{Package stringproc}
745
 
@closecatbox
746
 
 
747
 
@end deffn
748
 
 
749
 
@c -----------------------------------------------------------------------------
750
 
@anchor{base64_decode}
751
 
@deffn {Function} base64_decode (@var{base64-string})
752
 
 
753
 
Decodes the string @var{base64-string} coded in base64 back to the original string.
754
 
 
755
 
Example: See @ref{base64}.
756
 
 
757
 
@opencatbox
758
 
@category{Package stringproc}
759
 
@closecatbox
760
 
 
761
 
@end deffn
 
726
@node String Processing, Octets and Utilities for Cryptography, Characters, stringproc
 
727
@section String Processing
 
728
 
762
729
 
763
730
@c -----------------------------------------------------------------------------
764
731
@deffn {Function} charat (@var{string}, @var{n}) 
829
796
@end deffn
830
797
 
831
798
@c -----------------------------------------------------------------------------
832
 
@anchor{md5sum}
833
 
@deffn {Function} md5sum (@var{string})
834
 
 
835
 
Returns the md5 checksum of a @var{string}. 
836
 
The return value is a string to guarantee 32 hex characters. To parse the returned 
837
 
value into an integer please set the input base to 16 and prefix the string by zero.
838
 
 
839
 
Example:
840
 
 
841
 
@example
842
 
(%i1) string : md5sum("foo bar baz");
843
 
(%o1)                  ab07acbb1e496801937adfa772424bf7
844
 
(%i2) ibase : obase : 16.$
845
 
 
846
 
(%i3) integer : parse_string(sconcat(0, string));
847
 
(%o3)                 0ab07acbb1e496801937adfa772424bf7
848
 
@end example
849
 
 
850
 
@opencatbox
851
 
@category{Package stringproc}
852
 
@closecatbox
853
 
 
854
 
@end deffn
855
 
 
856
 
@c -----------------------------------------------------------------------------
857
799
@deffn {Function} parse_string (@var{str})
858
800
Parse the string @var{str} as a Maxima expression (do not evaluate it).
859
801
The string @var{str} may or may not have a terminator (dollar sign @code{$} or semicolon @code{;}).
933
875
@end deffn
934
876
 
935
877
@c -----------------------------------------------------------------------------
936
 
@anchor{sha1sum}
937
 
@deffn {Function} sha1sum (@var{string})
938
 
 
939
 
Returns the sha1 fingerprint of a @var{string}. 
940
 
The return value is a string to guarantee 48 hex characters. To parse the returned 
941
 
value into an integer please set the input base to 16 and prefix the string by zero.
942
 
 
943
 
Example:
944
 
 
945
 
@example
946
 
(%i1) string : sha1sum("foo bar baz");
947
 
(%o1)              c7567e8b39e2428e38bf9c9226ac68de4c67dc39
948
 
(%i2) ibase : obase : 16.$
949
 
 
950
 
(%i3) integer : parse_string(sconcat(0, string));
951
 
(%o3)              0c7567e8b39e2428e38bf9c9226ac68de4c67dc39
952
 
@end example
953
 
 
954
 
@opencatbox
955
 
@category{Package stringproc}
956
 
@closecatbox
957
 
 
958
 
@end deffn
959
 
 
960
 
@c -----------------------------------------------------------------------------
961
878
@deffn {Function} simplode @
962
879
@fname{simplode} (@var{list})   @
963
880
@fname{simplode} (@var{list}, @var{delim})  
1398
1315
@closecatbox
1399
1316
 
1400
1317
@end deffn
 
1318
 
 
1319
@c -----------------------------------------------------------------------------
 
1320
@node Octets and Utilities for Cryptography,  , String Processing, stringproc
 
1321
@section Octets and Utilities for Cryptography
 
1322
 
 
1323
@c -----------------------------------------------------------------------------
 
1324
@anchor{base64}
 
1325
@deffn {Function} base64 (@var{arg})
 
1326
 
 
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.
 
1329
 
 
1330
Example:
 
1331
 
 
1332
@example
 
1333
(%i1) base64: base64("foo bar baz");
 
1334
(%o1)                          Zm9vIGJhciBiYXo=
 
1335
(%i2) string: base64_decode(base64);
 
1336
(%o2)                            foo bar baz
 
1337
(%i3) obase: 16.$
 
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]
 
1342
(%i6) ibase: 16.$
 
1343
(%i7) base64(octets);
 
1344
(%o7)                          Zm9vIGJhciBiYXo=
 
1345
@end example
 
1346
 
 
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.
 
1350
 
 
1351
@opencatbox
 
1352
@category{Package stringproc}
 
1353
@closecatbox
 
1354
 
 
1355
@end deffn
 
1356
 
 
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})
 
1362
 
 
1363
By default @code{base64_decode} decodes the @var{base64-string} back to the original string. 
 
1364
 
 
1365
The optional argument @var{return-type} allows @code{base64_decode} to 
 
1366
alternatively return the corresponding number or list of octets.
 
1367
 
 
1368
Example: See @ref{base64}.
 
1369
 
 
1370
@opencatbox
 
1371
@category{Package stringproc}
 
1372
@closecatbox
 
1373
 
 
1374
@end deffn
 
1375
 
 
1376
@c -----------------------------------------------------------------------------
 
1377
@anchor{crc24sum}
 
1378
@deffn {Function} crc24sum @
 
1379
@fname{crc24sum} (@var{octets}) @
 
1380
@fname{crc24sum} (@var{octets}, @var{return-type})
 
1381
 
 
1382
By default @code{crc24sum} returns the @code{CRC24} checksum of an octet-list 
 
1383
as a string.
 
1384
 
 
1385
The optional argument @var{return-type} allows @code{crc24sum} to 
 
1386
alternatively return the corresponding number or list of octets.
 
1387
 
 
1388
Example:
 
1389
@example
 
1390
-----BEGIN PGP SIGNATURE-----
 
1391
Version: GnuPG v2.0.22 (GNU/Linux)
 
1392
 
 
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=
 
1399
=WmeC
 
1400
-----END PGP SIGNATURE-----
 
1401
@end example
 
1402
 
 
1403
@example
 
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);
 
1414
(%o4)                          [5A, 67, 82]
 
1415
(%i5) base64(crc24);
 
1416
(%o5)                              WmeC
 
1417
@end example
 
1418
 
 
1419
@opencatbox
 
1420
@category{Package stringproc}
 
1421
@closecatbox
 
1422
 
 
1423
@end deffn
 
1424
 
 
1425
@c -----------------------------------------------------------------------------
 
1426
@anchor{md5sum}
 
1427
@deffn {Function} md5sum @
 
1428
@fname{md5sum} (@var{arg}) @
 
1429
@fname{md5sum} (@var{arg}, @var{return-type})
 
1430
 
 
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.
 
1433
 
 
1434
The optional argument @var{return-type} allows @code{md5sum} to alternatively 
 
1435
return the corresponding number or list of octets.
 
1436
 
 
1437
Example:
 
1438
 
 
1439
@example
 
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
 
1450
@end example
 
1451
 
 
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.
 
1454
 
 
1455
@opencatbox
 
1456
@category{Package stringproc}
 
1457
@closecatbox
 
1458
 
 
1459
@end deffn
 
1460
 
 
1461
@c -----------------------------------------------------------------------------
 
1462
@anchor{number_to_octets}
 
1463
@deffn {Function} number_to_octets (@var{number})
 
1464
 
 
1465
Returns an octet-representation of @var{number} as a list of octets.
 
1466
The @var{number} must be a non-negative integer.
 
1467
 
 
1468
Example:
 
1469
 
 
1470
@example
 
1471
(%i1) ibase : obase : 16.$
 
1472
(%i2) octets: [0ca,0fe,0ba,0be]$
 
1473
(%i3) number: octets_to_number(octets);
 
1474
(%o3)                            0cafebabe
 
1475
(%i4) number_to_octets(number);
 
1476
(%o4)                      [0CA, 0FE, 0BA, 0BE]
 
1477
@end example
 
1478
 
 
1479
@opencatbox
 
1480
@category{Package stringproc}
 
1481
@closecatbox
 
1482
 
 
1483
@end deffn
 
1484
 
 
1485
@c -----------------------------------------------------------------------------
 
1486
@anchor{octets_to_number}
 
1487
@deffn {Function} octets_to_number (@var{octets})
 
1488
 
 
1489
Returns a number by concatenating the octets in the list of @var{octets}.
 
1490
 
 
1491
Example: See @ref{number_to_octets}.
 
1492
 
 
1493
@opencatbox
 
1494
@category{Package stringproc}
 
1495
@closecatbox
 
1496
 
 
1497
@end deffn
 
1498
 
 
1499
@c -----------------------------------------------------------------------------
 
1500
@anchor{octets_to_oid}
 
1501
@deffn {Function} octets_to_oid (@var{octets})
 
1502
 
 
1503
Computes an object identifier (OID) from the list of @var{octets}.
 
1504
 
 
1505
Example: RSA encryption OID
 
1506
 
 
1507
@example
 
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]
 
1513
@end example
 
1514
 
 
1515
@opencatbox
 
1516
@category{Package stringproc}
 
1517
@closecatbox
 
1518
 
 
1519
@end deffn
 
1520
 
 
1521
@c -----------------------------------------------------------------------------
 
1522
@anchor{oid_to_octets}
 
1523
@deffn {Function} oid_to_octets (@var{oid-string})
 
1524
 
 
1525
Convertes an object identifier (OID) to a list of @var{octets}.
 
1526
 
 
1527
Example: See @ref{octets_to_oid}.
 
1528
 
 
1529
@opencatbox
 
1530
@category{Package stringproc}
 
1531
@closecatbox
 
1532
 
 
1533
@end deffn
 
1534
 
 
1535
@c -----------------------------------------------------------------------------
 
1536
@anchor{sha1sum}
 
1537
@deffn {Function} sha1sum @
 
1538
@fname{sha1sum} (@var{arg}) @
 
1539
@fname{sha1sum} (@var{arg}, @var{return-type})
 
1540
 
 
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.
 
1543
 
 
1544
The optional argument @var{return-type} allows @code{sha1sum} to alternatively 
 
1545
return the corresponding number or list of octets.
 
1546
 
 
1547
Example:
 
1548
 
 
1549
@example
 
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
 
1560
@end example
 
1561
 
 
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.
 
1564
 
 
1565
@opencatbox
 
1566
@category{Package stringproc}
 
1567
@closecatbox
 
1568
 
 
1569
@end deffn
 
1570
 
 
1571
@c -----------------------------------------------------------------------------
 
1572
@anchor{sha256sum}
 
1573
@deffn {Function} sha256sum @
 
1574
@fname{sha256sum} (@var{arg}) @
 
1575
@fname{sha256sum} (@var{arg}, @var{return-type})
 
1576
 
 
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.
 
1579
 
 
1580
The optional argument @var{return-type} allows @code{sha256sum} to alternatively 
 
1581
return the corresponding number or list of octets (see @ref{sha1sum}).
 
1582
 
 
1583
Example:
 
1584
 
 
1585
@example
 
1586
(%i1) string: sha256sum("foo bar baz");
 
1587
(%o1)  dbd318c1c462aee872f41109a4dfd3048871a03dedd0fe0e757ced57dad6f2d7
 
1588
@end example
 
1589
 
 
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.
 
1592
 
 
1593
@opencatbox
 
1594
@category{Package stringproc}
 
1595
@closecatbox
 
1596
 
 
1597
@end deffn