XSLT 2.0 sort using letters and numbers - xslt

I have a sequence of strings that look like this:
B5 C10 C8 D11 D13 D3 D7 D9 E12 E8
I did the <xsl:perform-sort and <xsl:sort, based on the default data-type="text" and it's working correctly. But I would like to further sort so that after the letter the values are sorted numerically:
B5 C8 C10 D3 D7 D9 D11 D13 E8 E12
Any suggestions on how to do that? Thanks!
Edited to add my code:
<xsl:variable name="pns1" as="xs:string*">
<xsl:perform-sort select="distinct-values($combo1/*:pin/*:pkg[$pos]/*:pn/#n)">
<xsl:sort select="."/>
</xsl:perform-sort>
</xsl:variable>
<xsl:variable name="pns2" as="xs:string*">
<xsl:perform-sort select="$pns1">
<xsl:sort select="." data-type="number"/>
</xsl:perform-sort>
</xsl:variable>
<xsl:message select="$pns2"/>

Saxon allows you a parameter alphanumeric="yes" on a collation URI, see https://www.saxonica.com/html/documentation11/localization/unicode-collation-algorithm/ so e.g.
'B5 C10 C8 D11 D13 D3 D7 D9 E12 E8'
=> tokenize('\s+')
=> sort('http://www.w3.org/2013/collation/UCA?alphanumeric=yes')
gives
B5 C8 C10 D3 D7 D9 D11 D13 E8 E12
.
Online fiddle with Saxon XQuery (but XPath/XSLT support it the same): https://xqueryfiddle.liberty-development.net/jyH9Xvk.
Using numeric=yes;fallback=yes might even give better compatibility between the various Saxon editions (HE, PE, EE) and platforms (Java, .NET):
'B5 C10 C8 D11 D13 D3 D7 D9 E12 E8'
=> tokenize('\s+')
=> sort('http://www.w3.org/2013/collation/UCA?numeric=yes;fallback=yes')
or even SaxonJS.

Consider the following example:
XSLT 2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="strings" select="('D13', 'B5', 'C10', 'E12', 'C8', 'D11', 'D3', 'E8', 'D7', 'D9')" />
<xsl:template match="/">
<result>
<xsl:perform-sort select="$strings">
<xsl:sort select="substring(., 1, 1)"/>
<xsl:sort select="substring(., 2)" data-type="number"/>
</xsl:perform-sort>
</result>
</xsl:template>
</xsl:stylesheet>
Result
<?xml version="1.0" encoding="UTF-8"?>
<result>B5 C8 C10 D3 D7 D9 D11 D13 E8 E12</result>

Related

How to generate RSA public key with no any API. Just using modulus and public exponent

How to generate RSA public key with no any API. Just using modulus and public exponent.
In our project we are implementing RSA PKCS#8 public key by modulus and public exponent.
However we don't know meaning of ASN.1 binary of PKCS#8 public key.
For understanding PKCS#8 public key ASN.1, we did blow.
1. openssl genrsa -out hoge.key 2048
2. openssl rsa -pubout -in hoge.key
Here we get below infomation.
> -----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7z2oyePt5vNbH7Pbieiw
BOgRnCUyyUvUo6Wi+uqUWvMxrji1vH21ViTZYLjg40RrulSCGFwjzwnI4AMtEdIZ
7uOol12E3xOZYNgwTBaDNCT9p0IYYuFVGfQyxlavr7oSIaaNmlSRy+0os1xi7IiI
PCHE/7nfifDQiqGtb6b6TBOwP3QXg5IdrXiqQJAlk+8S0XPhbnwwzWOhlrR3Wftq
jylBPSGSDJQoF0fJ5h2cA2yJiGqTV37YRTThPWmQEuz8Njx4bTaEaTul5/UNhSel
s7khd/IvHV9oN6T2o4V//fAsyjRZlYKEUHldb3ML/QHxWs7+hqWSa9NCwwXZGhEl
wwIDAQAB
-----END PUBLIC KEY-----
> 0000000 30 82 01 22 30 0d 06 09 2a 86 48 86 f7 0d 01 01
0000010 01 05 00 03 82 01 0f 00 30 82 01 0a 02 82 01 01
0000020 00 ef 3d a8 c9 e3 ed e6 f3 5b 1f b3 db 89 e8 b0
0000030 04 e8 11 9c 25 32 c9 4b d4 a3 a5 a2 fa ea 94 5a
0000040 f3 31 ae 38 b5 bc 7d b5 56 24 d9 60 b8 e0 e3 44
0000050 6b ba 54 82 18 5c 23 cf 09 c8 e0 03 2d 11 d2 19
0000060 ee e3 a8 97 5d 84 df 13 99 60 d8 30 4c 16 83 34
0000070 24 fd a7 42 18 62 e1 55 19 f4 32 c6 56 af af ba
0000080 12 21 a6 8d 9a 54 91 cb ed 28 b3 5c 62 ec 88 88
0000090 3c 21 c4 ff b9 df 89 f0 d0 8a a1 ad 6f a6 fa 4c
00000a0 13 b0 3f 74 17 83 92 1d ad 78 aa 40 90 25 93 ef
00000b0 12 d1 73 e1 6e 7c 30 cd 63 a1 96 b4 77 59 fb 6a
00000c0 8f 29 41 3d 21 92 0c 94 28 17 47 c9 e6 1d 9c 03
00000d0 6c 89 88 6a 93 57 7e d8 45 34 e1 3d 69 90 12 ec
00000e0 fc 36 3c 78 6d 36 84 69 3b a5 e7 f5 0d 85 27 a5
00000f0 b3 b9 21 77 f2 2f 1d 5f 68 37 a4 f6 a3 85 7f fd
0000100 f0 2c ca 34 59 95 82 84 50 79 5d 6f 73 0b fd 01
0000110 f1 5a ce fe 86 a5 92 6b d3 42 c3 05 d9 1a 11 25
0000120 c3 02 03 01 00 01
0000126
we understand above binary as below. However we don't understand some binary.So We would like to know meaning of ASN.1 binary of PKCS#8 public key.
By the way, We have already refer below information. However this does not mention about public key.
https://datatracker.ietf.org/doc/html/rfc5208
30: SEQUEENCE
82: next 2byte is sequence length
01 22: 0x122byte
30: SEWUENCE
0d:?
06:?
09:?
2a 86.. 01 01 01: PKCS#1 rsa Encryption
05: ?
00: ?
03: ?
82: next 2byte is length of bit string
01 0f: length of bit string
00: ?
30 82....: PKCS#1 public key
Taking a huge gamble that what you're really asking is how to obtain the modulus and public exponent from a RSA public key PEM encoding, I invite you on this tryst. If your looking to build this encoding given only the modulus and public exponent, this dissection should show you how it's laid out, and this a somewhat reverse roadmap to get there. Either way, read on.
First of all: "next 2byte is length of bit string" - that's rather assumptive of you. ASN.1 is all about type-length-value (TLV for short) and does not waver from that model. The only reason the "next 2 byte is length of bit string" is because the ASN.1 said it is. (more on that later).
ASN.1 in incredibly flexible. I recently had a colleague jokingly tell me "ASN.1 is just JSON for boomers". Yeah, I took that personally. Since JSON followed ASN.1 by decades, I like to think "JSON is just ASN.1 for millennials".
Anyway, funny thing about ASN.1 (and JSON, for that matter): sometimes there are TLV encodings within TLV encodings, and that is the case here. Specifically an RSAPublicKey sequence will be encoded in an ASN.1 bit-string provided the setup is correct (i.e. the OID matches), and that seems to be the part you're struggling with: how to find it.
I'm going to leave the actual code to do this (which will be tedious, no-doubt fraught with hackery, and ultimately leave you wishing you had just used a crypto-library) as a task. That said, on to the act ripping apart your public key. First, your PEM:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7z2oyePt5vNbH7Pbieiw
BOgRnCUyyUvUo6Wi+uqUWvMxrji1vH21ViTZYLjg40RrulSCGFwjzwnI4AMtEdIZ
7uOol12E3xOZYNgwTBaDNCT9p0IYYuFVGfQyxlavr7oSIaaNmlSRy+0os1xi7IiI
PCHE/7nfifDQiqGtb6b6TBOwP3QXg5IdrXiqQJAlk+8S0XPhbnwwzWOhlrR3Wftq
jylBPSGSDJQoF0fJ5h2cA2yJiGqTV37YRTThPWmQEuz8Njx4bTaEaTul5/UNhSel
s7khd/IvHV9oN6T2o4V//fAsyjRZlYKEUHldb3ML/QHxWs7+hqWSa9NCwwXZGhEl
wwIDAQAB
-----END PUBLIC KEY-----
Decoding the base64 to DER, then displayed through xxd, it looks like this:
00000000: 30 82 01 22 30 0d 06 09 2a 86 48 86 f7 0d 01 01 0.."0...*.H.....
00000010: 01 05 00 03 82 01 0f 00 30 82 01 0a 02 82 01 01 ........0.......
00000020: 00 ef 3d a8 c9 e3 ed e6 f3 5b 1f b3 db 89 e8 b0 ..=......[......
00000030: 04 e8 11 9c 25 32 c9 4b d4 a3 a5 a2 fa ea 94 5a ....%2.K.......Z
00000040: f3 31 ae 38 b5 bc 7d b5 56 24 d9 60 b8 e0 e3 44 .1.8..}.V$.`...D
00000050: 6b ba 54 82 18 5c 23 cf 09 c8 e0 03 2d 11 d2 19 k.T..\#.....-...
00000060: ee e3 a8 97 5d 84 df 13 99 60 d8 30 4c 16 83 34 ....]....`.0L..4
00000070: 24 fd a7 42 18 62 e1 55 19 f4 32 c6 56 af af ba $..B.b.U..2.V...
00000080: 12 21 a6 8d 9a 54 91 cb ed 28 b3 5c 62 ec 88 88 .!...T...(.\b...
00000090: 3c 21 c4 ff b9 df 89 f0 d0 8a a1 ad 6f a6 fa 4c <!..........o..L
000000a0: 13 b0 3f 74 17 83 92 1d ad 78 aa 40 90 25 93 ef ..?t.....x.#.%..
000000b0: 12 d1 73 e1 6e 7c 30 cd 63 a1 96 b4 77 59 fb 6a ..s.n|0.c...wY.j
000000c0: 8f 29 41 3d 21 92 0c 94 28 17 47 c9 e6 1d 9c 03 .)A=!...(.G.....
000000d0: 6c 89 88 6a 93 57 7e d8 45 34 e1 3d 69 90 12 ec l..j.W~.E4.=i...
000000e0: fc 36 3c 78 6d 36 84 69 3b a5 e7 f5 0d 85 27 a5 .6<xm6.i;.....'.
000000f0: b3 b9 21 77 f2 2f 1d 5f 68 37 a4 f6 a3 85 7f fd ..!w./._h7......
00000100: f0 2c ca 34 59 95 82 84 50 79 5d 6f 73 0b fd 01 .,.4Y...Py]os...
00000110: f1 5a ce fe 86 a5 92 6b d3 42 c3 05 d9 1a 11 25 .Z.....k.B.....%
00000120: c3 02 03 01 00 01 ......
Regular ASN.1 encoding, as expected. For a PKCS8 encoded key, it should look like this:
PublicKeyInfo ::= SEQUENCE {
algorithm AlgorithmIdentifier,
PublicKey BIT STRING
}
Sending our base64-decoded DER data through ASN.1 decoding, we see::
openssl asn1parse -in pubkey.der -inform DER
0:d=0 hl=4 l= 290 cons: SEQUENCE
4:d=1 hl=2 l= 13 cons: SEQUENCE
6:d=2 hl=2 l= 9 prim: OBJECT :rsaEncryption
17:d=2 hl=2 l= 0 prim: NULL
19:d=1 hl=4 l= 271 prim: BIT STRING
That looks about right. For an RSA public key, the OID is 1.2.840.113549.1.1.1, the NULL, then what should be a RSAPublicKey as the PublicKey key data bit-string, which will look like this:
RSAPublicKey ::= SEQUENCE {
modulus INTEGER, -- n
publicExponent INTEGER -- e
}
From the aforementioned decoding, we know at offset 19 is the actual bit string, which should contain the RSAPublicKey ASN.1 structure. Great, but how? Well, the original parse has the following at offset-19 of the file:
00000010: 01 05 00 03 82 01 0f 00 30 82 01 0a 02 82 01 01 ........0.......
^^^^^^^^^^^^^^
From this we get:
The ASN.1 tag byte, 03, says its a bit-string. Good. We expected that. then...
The length is calculated. Per ASN.1 rules, if the length octet has the high bit lit, it means the remaining bits of that octet tell how many subsequent octets make up the actual length (i.e it can be a multi-byte length). 82 means two octets follow, indicating
the bit-string overall object length: 010f, e.g. 271 bytes.
Immediately following the length description will be a single octet stating the number of padding bits of the bit-string. I can honestly say in a quarter century of staring at these I have never seen this any value other than zero (00) in any RSA encoded public key, but still worth mentioning.
Thereafter is the actual RSAPublicKey ASN.1 structure itself. Past the bit-string type-length-padding description, we can parse the actual RSAPublicKey (finally!). The bit-string content after the type-length and padding bits indicator should be just that. Well, that's at offset 24 of our DER-encoding, so:
openssl asn1parse -in pubkey.der -inform DER -offset 24
0:d=0 hl=4 l= 266 cons: SEQUENCE
4:d=1 hl=4 l= 257 prim: INTEGER :EF3DA8C9E3EDE6F35B1FB3DB89E8B004E8119C2532C94BD4A3A5A2FAEA945AF331AE38B5BC7DB55624D960B8E0E3446BBA5482185C23CF09C8E0032D11D219EEE3A8975D84DF139960D8304C16833424FDA7421862E15519F432C656AFAFBA1221A68D9A5491CBED28B35C62EC88883C21C4FFB9DF89F0D08AA1AD6FA6FA4C13B03F741783921DAD78AA40902593EF12D173E16E7C30CD63A196B47759FB6A8F29413D21920C94281747C9E61D9C036C89886A93577ED84534E13D699012ECFC363C786D3684693BA5E7F50D8527A5B3B92177F22F1D5F6837A4F6A3857FFDF02CCA345995828450795D6F730BFD01F15ACEFE86A5926BD342C305D91A1125C3
265:d=1 hl=2 l= 3 prim: INTEGER :010001
Sure enough, there it is, the modulus and the exponent as expected. Extracting and decoding from there is just a matter of code, but at least now it is code based on decoding by calculation and not guessing.
Fair Warning
The only reason why this worked is because we knew the RSAPublicKey was in the bit string, and the only reason we knew that was because the OID says it was. The form stored in the bit-string is dependent on that OID, so make sure to check it first before assuming the bit-string is RSAPublicKey material.
You are asking how to generate a public key, but I don't understand why you show some binary data you are trying to decode. You can not learn how to generate a public or private key from looking at binary data which i assume is already encrypted.
Why not use a library to generate a key pair and be done with it? Trying to code something yourself, from scratch, is likely (very likely in fact) to have errors which lead to really insecure conditions.
In any event, you can download the source code to ssl libraries like openssl if you want to see what you can learn from them.

How to modify a SVG attribute using XSLT

How can I modify a SVG file by using XSLT?
I like to modify the following SVG (cutout) file:
<svg width="834px" height="707.5px" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" overflow="visible">
<defs>
<symbol id="E003" viewBox="0 0 1000 1000" overflow="inherit">
<path transform="scale(1,-1)" d="M0 -0c49 0 97.5 -2.26367 135.5 4.73633c206 95 258.5 264.264 263.5 271.264c0 1 -14 7 -15 6c-88 -154 -251 -167 -321 -170c-1 0 -63 -1 -63 -1v-111z" />
</symbol>
<symbol id="E004" viewBox="0 0 1000 1000" overflow="inherit">
<path transform="scale(1,-1)" d="M0 0c49 0 97.5 2.26367 135.5 -4.73633c206 -95 258.5 -264.264 263.5 -271.264c0 -1 -14 -7 -15 -6c-88 154 -251 167 -321 170c-1 0 -63 1 -63 1v111z" />
</symbol>
<symbol id="E050" viewBox="0 0 1000 1000" overflow="inherit">
<path transform="scale(1,-1)" d="M441 -245c-23 -4 -48 -6 -76 -6c-59 0 -102 7 -130 20c-88 42 -150 93 -187 154c-26 44 -43 103 -48 176c-4 60 11 123 44 189c29 57 65 106 110 148s96 85 153 127c-3 16 -8 46 -13 92c-4 43 -5 73 -5 89c0 117 16 172 69 257c34 54 64 82 89 82c21 0 43 -30 69 -92 s39 -115 41 -159c2 -120 -19 -173 -67 -256c-13 -20 -63 -90 -98 -118c-13 -9 -25 -19 -37 -29l31 -181c8 1 18 2 28 2c58 0 102 -12 133 -35c59 -43 92 -104 98 -184c11 -135 -80 -229 -180 -270c8 -57 17 -110 25 -162c5 -31 6 -58 6 -80c0 -30 -5 -53 -14 -70 c-35 -64 -88 -99 -158 -103c-42 -3 -83 6 -124 26c-50 24 -77 59 -80 105c-2 34 5 63 20 87c18 28 45 42 79 44c51 4 99 -40 103 -87c4 -56 -30 -94 -105 -115c17 -24 51 -36 102 -36c62 0 116 43 140 85c9 16 13 41 13 74c0 20 -1 42 -5 67c-8 53 -18 106 -26 159zM461 939 c-95 0 -135 -175 -135 -286c0 -24 2 -48 5 -71c50 39 92 82 127 128c43 57 63 106 60 148c-4 54 -23 82 -57 81zM406 119l54 -326c80 27 116 88 109 184c-7 99 -62 146 -163 142zM382 117c-74 -2 -132 -50 -128 -127c2 -46 43 -99 75 -115c-3 -2 -7 -5 -10 -10 c-70 33 -116 88 -123 172c-5 73 42 135 88 170c23 17 49 29 78 36l-29 170c-21 -13 -52 -37 -92 -73c-50 -44 -86 -84 -109 -119c-49 -75 -71 -140 -67 -195c5 -68 35 -127 93 -176s125 -73 203 -73c25 0 50 3 75 9c-19 111 -36 221 -54 331z" />
</symbol>
<symbol id="E260" viewBox="0 0 1000 1000" overflow="inherit">
<path transform="scale(1,-1)" d="M20 110c32 16 54 27 93 27c26 0 35 -3 54 -13c13 -7 24 -20 27 -38l4 -25c0 -28 -16 -57 -45 -89c-23 -25 -39 -44 -65 -68l-88 -79v644h20v-359zM90 106c-32 0 -48 -10 -70 -29v-194c31 31 54 59 71 84c21 32 32 59 32 84c0 9 1 16 1 20c0 14 -3 21 -11 30l-8 3z" />
</symbol>
<symbol id="E0A4" viewBox="0 0 1000 1000" overflow="inherit">
<path transform="scale(1,-1)" d="M0 -39c0 68 73 172 200 172c66 0 114 -37 114 -95c0 -84 -106 -171 -218 -171c-64 0 -96 30 -96 94z" />
</symbol>
<symbol id="E262" viewBox="0 0 1000 1000" overflow="inherit">
<path transform="scale(1,-1)" d="M136 186v169h17v-164l44 14v-91l-44 -14v-165l44 12v-91l-44 -13v-155h-17v150l-76 -22v-155h-17v149l-43 -13v90l43 14v167l-43 -14v92l43 13v169h17v-163zM60 73v-167l76 22v168z" />
</symbol>
</defs>
<style type="text/css">g.page-margin{font-family:Times;} g.tempo{font-weight:bold;} g.dir, g.dynam, g.mNum{font-style:italic;} g.label{font-weight:normal;}</style>
<svg class="definition-scale" viewBox="0 0 16680 14150">
<g class="page-margin" transform="translate(500, 500)">
<g class="system" id="system-0000000155158177">
<path d="M2099 720 L2099 5782" stroke="#000000" stroke-width="27" />
<use xlink:href="#E003" x="1919" y="720" height="720px" width="720px" />
<use xlink:href="#E004" x="1919" y="5782" height="720px" width="720px" />
<rect x="1919" y="702" height="5098" width="90" />
<use xlink:href="#E003" x="1797" y="720" height="720px" width="720px" />
<use xlink:href="#E004" x="1797" y="2880" height="720px" width="720px" />
<rect x="1797" y="702" height="2196" width="90" />
<g class="labelAbbr" id="labelAbbr-0000001982553912">
<text x="1546" y="1170" text-anchor="end" font-size="0px">
<tspan class="text" id="text-0000000427332132">
<tspan font-size="405px" class="text">C Tpt. 1</tspan>
</tspan>
</text>
</g>
<g class="labelAbbr" id="labelAbbr-0000001715657114">
<text x="1546" y="2610" text-anchor="end" font-size="0px">
<tspan class="text" id="text-0000000786186729">
<tspan font-size="405px" class="text">C Tpt. 2</tspan>
</tspan>
</text>
</g>
<g class="labelAbbr" id="labelAbbr-0000000404188205">
<text x="1816" y="4072" text-anchor="end" font-size="0px">
<tspan class="text" id="text-0000000700385974">
<tspan font-size="405px" class="text">Tbn.</tspan>
</tspan>
</text>
</g>
<g class="labelAbbr" id="labelAbbr-0000001796530924">
<text x="1816" y="5512" text-anchor="end" font-size="0px">
<tspan class="text" id="text-0000000675162848">
<tspan font-size="405px" class="text">B. Tbn.</tspan>
</tspan>
</text>
</g>
<g class="sb" id="sb-0000001000252933" />
<g class="measure" id="d1e4299">
<g class="mNum autogenerated" id="mnum-0000001212157683">
<text x="2086" y="450" text-anchor="middle" font-size="0px">
<tspan class="text" id="text-0000001704302739">
<tspan font-size="324px" class="text">22</tspan>
</tspan>
</text>
</g>
<g class="staff" id="staff-0000001329456927">
<path d="M2086 720 L7292 720" stroke="#000000" stroke-width="13" />
<path d="M2086 900 L7292 900" stroke="#000000" stroke-width="13" />
<path d="M2086 1080 L7292 1080" stroke="#000000" stroke-width="13" />
<path d="M2086 1260 L7292 1260" stroke="#000000" stroke-width="13" />
<path d="M2086 1440 L7292 1440" stroke="#000000" stroke-width="13" />
<g class="clef" id="clef-0000001591308631">
<use xlink:href="#E050" x="2176" y="1260" height="720px" width="720px" />
</g>
<g class="keySig" id="keysig-0000000362821479">
<use xlink:href="#E260" x="2857" y="1080" height="720px" width="720px" />
</g>
<g class="layer" id="layer-0000001762708701">
<g class="note" id="d1e4305">
<use xlink:href="#E0A4" x="3559" y="1350" height="720px" width="720px" />
<g class="stem">
<rect x="3767" y="720" height="608" width="18" />
</g>
<g class="accid" id="accid-0000001439359008">
<use xlink:href="#E262" x="3364" y="1350" height="720px" width="720px" />
</g>
</g>
<g class="note" id="d1e4323">
<use xlink:href="#E0A4" x="4423" y="1350" height="720px" width="720px" />
<g class="stem">
<rect x="4631" y="720" height="608" width="18" />
</g>
<g class="accid" id="accid-0000000550318292" />
</g>
<g class="note" id="d1e4339">
<use xlink:href="#E0A4" x="5551" y="1260" height="720px" width="720px" />
<g class="stem">
<rect x="5759" y="630" height="608" width="18" />
</g>
</g>
<g class="note" id="d1e4353">
<use xlink:href="#E0A4" x="6415" y="900" height="720px" width="720px" />
<g class="stem">
<rect x="6415" y="922" height="608" width="18" />
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</svg>
</svg>
I want to change the color for the symbol id="E050". To achieve this I tried to add the attribute fill="#ff0000" to the symbol definition.
This is the current version of my XSL file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg">
<xsl:template match="node() | #*">
<xsl:copy>
<xsl:apply-templates select="node() | #*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//symbol[#id='E050']">
<xsl:copy>
<xsl:apply-templates select="#*"/>
<xsl:attribute name="fill">#ff0000</xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
How can I modify the XSL file that the color for the symbol id="E050 is changed but the rest is not modified?
To test the modification I'm using the online tool https://www.w3schools.com/xml/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog_ex1.
Change this line...
<xsl:template match="//symbol[#id='E050']">
To this line....
<xsl:template match="svg:symbol[#id='E050']">
(Note the // prefix is not necessary in a template match)
Although you have a default namespace declaration in your XSLT (xmlns="http://www.w3.org/2000/svg") this only applies to unprefixed elements in your XSLT (which also happens to be an XML document), not Xpath expressions in attributes. This doing a match on symbol[#id='E050'] is trying to match a symbol element in no namespace.
Alternatively, if you could use XSLT 2.0, you could add this line to the xsl:stylesheet element, as this would then mean unprefixed element names in xpath expressions would be given a namespace
xpath-default-namespace="http://www.w3.org/2000/svg"

Merging lines in chess ply sequences

I have a file containing the ply sequences of multiple chess games. Games are separated by one or more new lines and the corresponding ply sequence of each game can be also split into multiple lines.
I would like to merge all lines corresponding to the same game, so as to have only one line per game. I have tried different options, but none worked. A remark is that the file contains more than 14M games, so I need a fast solution. I work on Linux.
Example:
e4 e5 Bb5 c6 Bc4 b5 Bxf7+ Kxf7 Nf3 Qf6 d4 d6 dxe5 dxe5
Bg5 Qe6 Nc3 Be7 Be3 Nf6 b4 Rd8 Ng5+ Kg8 Nd5 Qd6 Qf3 cxd5
Bc5 Qe6 Nxe6 Bxe6 Bxe7
e4 e5 Nf3 Qf6 Bc4 Bc5 Nc3 c6 Na4 Bb4 c3 Ba5 Nc5 d6 Nb3
Bb6 d4 h6 dxe5 dxe5 O-O Ne7 Be3 Nd7 Bxb6 Nxb6 Be2 O-O
Nc5 Ng6 b4 Nf4 Nd3 Rd8 Qc2 Nc4 Nxf4 Na3 Qb3 Qxf4
Qxa3 Qxe4 Rfe1 f6 Qb3+ Kh8 Bd1 Qf4 Bc2 Bg4 Re4 Qf5 Rxe5
Qd7 Re3 Qd6 Nh4 Qd5 Ng6+ Kh7 Ne7+ f5 Nxd5 Rxd5 c4 Rd2
h3 Bh5 Bxf5+ Kh8
e4 e5 Nf3 Nc6 Bb5 Nf6 Bxc6 bxc6 O-O d6 h3 Nxe4 Re1 Bf5
d4 f6 dxe5 fxe5 Nbd2 Nxd2 Bxd2 Be7 Qc1 O-O c3 h6 c4 e4
Nd4 Qd7 b3 d5 Nxf5 Qxf5 Be3 Bf6 Rb1 d4 Bd2 c5
d4 Nf6 Nc3 d5 Bg5 Ne4 Nxe4 dxe4 c3 h6 Be3 e6 Qc2 f5 g4
Be7 Bg2 O-O O-O-O Nd7 d5 Nb6 dxe6 Qe8 gxf5 Rxf5 Bxe4 Rf8
Bh7+ Kh8 Bg6
Should become:
e4 e5 Bb5 c6 Bc4 b5 Bxf7+ Kxf7 Nf3 Qf6 d4 d6 dxe5 dxe5 Bg5 Qe6 Nc3 Be7 Be3 Nf6 b4 Rd8 Ng5+ Kg8 Nd5 Qd6 Qf3 cxd5 Bc5 Qe6 Nxe6 Bxe6 Bxe7
e4 e5 Nf3 Qf6 Bc4 Bc5 Nc3 c6 Na4 Bb4 c3 Ba5 Nc5 d6 Nb3 Bb6 d4 h6 dxe5 dxe5 O-O Ne7 Be3 Nd7 Bxb6 Nxb6 Be2 O-O Nc5 Ng6 b4 Nf4 Nd3 Rd8 Qc2 Nc4 Nxf4 Na3 Qb3 Qxf4 Qxa3 Qxe4 Rfe1 f6 Qb3+ Kh8 Bd1 Qf4 Bc2 Bg4 Re4 Qf5 Rxe5 Qd7 Re3 Qd6 Nh4 Qd5 Ng6+ Kh7 Ne7+ f5 Nxd5 Rxd5 c4 Rd2 h3 Bh5 Bxf5+ Kh8
e4 e5 Nf3 Nc6 Bb5 Nf6 Bxc6 bxc6 O-O d6 h3 Nxe4 Re1 Bf5 d4 f6 dxe5 fxe5 Nbd2 Nxd2 Bxd2 Be7 Qc1 O-O c3 h6 c4 e4 Nd4 Qd7 b3 d5 Nxf5 Qxf5 Be3 Bf6 Rb1 d4 Bd2 c5
d4 Nf6 Nc3 d5 Bg5 Ne4 Nxe4 dxe4 c3 h6 Be3 e6 Qc2 f5 g4 Be7 Bg2 O-O O-O-O Nd7 d5 Nb6 dxe6 Qe8 gxf5 Rxf5 Bxe4 Rf8 Bh7+ Kh8 Bg6
With awk, you can set the record separator to the empty string, which makes records being separated by blank lines. Then you replace for each record the newlines with a space:
awk -v RS="" '{gsub("\n", " ")} 1' infile
Or, as an alternative, with sed:
sed ':a;N;/\n$/!s/\n//;ta;s/\n$//;/^$/d' infile
This works as follows:
:label # Label to jump back to
N # Append next line to pattern sapce
/\n$/! s/\n// # If pattern space does not end with newline, remove newline
t label # Jump back to label if we changed something
s/\n$// # Remove trailing newline
/^$/ d # Delete empty line
The last command isn't strictly necessary for the given input, but if there are more than two consecutive empty lines, there would be empty output lines without it. It's just there to make the sed command equivalent to the awk command.

create new structure and move elements with xslt

I have a rather badly formatted input xml that needs to be reorganized using xslt 1.0.
The hierarchy must be changed so that detail lines are divided in an upper and lower part, each containing a left and right part. I failed to create the desired output until now.
Can someone help me out, thanks in advance.
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<document>
<Header_Label_Header_1>
<Label_Header_Header_Company>1001</Label_Header_Header_Company>
<Label_Header_Header_Unique_Sequence_Number>1</Label_Header_Header_Unique_Sequence_Number>
<Detail_Line>
<Line_Print_Description_1>PAR Wdfl Vivida bianco strukt.</Line_Print_Description_1>
<Line_Print_Description_2>30x60cm</Line_Print_Description_2>
</Detail_Line>
<Detail_Line>
<Line_Print_Description_1>PAR Wdfl Secret bianco 1.</Line_Print_Description_1>
<Line_Print_Description_2>29,5x59,5cm</Line_Print_Description_2>
</Detail_Line>
</Header_Label_Header_1>
<Header_Label_Header_2>
<Label_Header_Header_Company>00500</Label_Header_Header_Company>
<Label_Header_Header_Unique_Sequence_Number>2</Label_Header_Header_Unique_Sequence_Number>
<Detail_Line>
<Line_Print_Description_1>IRS Fstzg Porcelainw.Brownwood</Line_Print_Description_1>
<Line_Print_Description_2>frb. R9, 15x120cm</Line_Print_Description_2>
</Detail_Line>
<Detail_Line>
<Line_Print_Description_1>IRS Fstzg Porcelainw.Greywood</Line_Print_Description_1>
<Line_Print_Description_2>frb. R9, 15x120cm</Line_Print_Description_2>
</Detail_Line>
<Detail_Line>
<Line_Print_Description_1>IRS Fstzg Porcelainw.Blackwood</Line_Print_Description_1>
<Line_Print_Description_2>frb. R9, 15x120cm</Line_Print_Description_2>
</Detail_Line>
</Header_Label_Header_2>
<Header_Label_Header_3>
<Label_Header_Header_Company>00500</Label_Header_Header_Company>
<Label_Header_Header_Unique_Sequence_Number>3</Label_Header_Header_Unique_Sequence_Number>
<Detail_Line>
<Line_Print_Description_1>RAK Fstzg Ardesia black gl.str</Line_Print_Description_1>
<Line_Print_Description_2>frb, R9, 30x60cm</Line_Print_Description_2>
</Detail_Line>
</Header_Label_Header_3>
<Header_Label_Header_4>
<Label_Header_Header_Company>00500</Label_Header_Header_Company>
<Label_Header_Header_Unique_Sequence_Number>4</Label_Header_Header_Unique_Sequence_Number>
<Detail_Line>
<Line_Print_Description_1>BAUMIT KlebeSpachtel 25kg</Line_Print_Description_1>
<Line_Print_Description_2></Line_Print_Description_2>
</Detail_Line>
</Header_Label_Header_4>
<Header_Label_Header_1>
<Label_Header_Header_Company>1001</Label_Header_Header_Company>
<Label_Header_Header_Unique_Sequence_Number>1</Label_Header_Header_Unique_Sequence_Number>
<Detail_Line>
<Line_Print_Description_1>PAR Wdfl Vivida bianco strukt.</Line_Print_Description_1>
<Line_Print_Description_2>30x60cm</Line_Print_Description_2>
</Detail_Line>
<Detail_Line>
<Line_Print_Description_1>PAR Wdfl Secret bianco 1.</Line_Print_Description_1>
<Line_Print_Description_2>29,5x59,5cm</Line_Print_Description_2>
</Detail_Line>
</Header_Label_Header_1>
<Header_Label_Header_2>
<Label_Header_Header_Company>00500</Label_Header_Header_Company>
<Label_Header_Header_Unique_Sequence_Number>2</Label_Header_Header_Unique_Sequence_Number>
<Detail_Line>
<Line_Print_Description_1>IRS Fstzg Porcelainw.Brownwood</Line_Print_Description_1>
<Line_Print_Description_2>frb. R9, 15x120cm</Line_Print_Description_2>
</Detail_Line>
<Detail_Line>
<Line_Print_Description_1>IRS Fstzg Porcelainw.Greywood</Line_Print_Description_1>
<Line_Print_Description_2>frb. R9, 15x120cm</Line_Print_Description_2>
</Detail_Line>
<Detail_Line>
<Line_Print_Description_1>IRS Fstzg Porcelainw.Blackwood</Line_Print_Description_1>
<Line_Print_Description_2>frb. R9, 15x120cm</Line_Print_Description_2>
</Detail_Line>
</Header_Label_Header_2>
<Header_Label_Header_3>
<Label_Header_Header_Company>00500</Label_Header_Header_Company>
<Label_Header_Header_Unique_Sequence_Number>3</Label_Header_Header_Unique_Sequence_Number>
<Detail_Line>
<Line_Print_Description_1>RAK Fstzg Ardesia black gl.str</Line_Print_Description_1>
<Line_Print_Description_2>frb, R9, 30x60cm</Line_Print_Description_2>
</Detail_Line>
</Header_Label_Header_3>
<Header_Label_Header_4>
<Label_Header_Header_Company>00500</Label_Header_Header_Company>
<Label_Header_Header_Unique_Sequence_Number>4</Label_Header_Header_Unique_Sequence_Number>
<Detail_Line>
<Line_Print_Description_1>BAUMIT KlebeSpachtel 25kg</Line_Print_Description_1>
<Line_Print_Description_2></Line_Print_Description_2>
</Detail_Line>
</Header_Label_Header_4>
</document>
The output must be like this:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<document>
<Header_Label_Upper>
<Label_Left>
<Label_Header_Header_Company>1001</Label_Header_Header_Company>
<Label_Header_Header_Unique_Sequence_Number>1</Label_Header_Header_Unique_Sequence_Number>
</Label_Left>
<Detail_Line_Left>
<Line_Print_Description_1>PAR Wdfl Vivida bianco strukt.</Line_Print_Description_1>
<Line_Print_Description_2>30x60cm</Line_Print_Description_2>
</Detail_Line_Left>
<Detail_Line_Left>
<Line_Print_Description_1>PAR Wdfl Secret bianco 1.</Line_Print_Description_1>
<Line_Print_Description_2>29,5x59,5cm</Line_Print_Description_2>
</Detail_Line_Left>
<Label_Right>
<Label_Header_Header_Company>00500</Label_Header_Header_Company>
<Label_Header_Header_Unique_Sequence_Number>2</Label_Header_Header_Unique_Sequence_Number>
</Label_Right>
<Detail_Line_Right>
<Line_Print_Description_1>IRS Fstzg Porcelainw.Brownwood</Line_Print_Description_1>
<Line_Print_Description_2>frb. R9, 15x120cm</Line_Print_Description_2>
</Detail_Line_Right>
<Detail_Line_Right>
<Line_Print_Description_1>IRS Fstzg Porcelainw.Greywood</Line_Print_Description_1>
<Line_Print_Description_2>frb. R9, 15x120cm</Line_Print_Description_2>
</Detail_Line_Right>
<Detail_Line_Right>
<Line_Print_Description_1>IRS Fstzg Porcelainw.Blackwood</Line_Print_Description_1>
<Line_Print_Description_2>frb. R9, 15x120cm</Line_Print_Description_2>
</Detail_Line_Right>
</Header_Label_Upper>
<Header_Label_Lower>
<Label_Left>
<Label_Header_Header_Company>00500</Label_Header_Header_Company>
<Label_Header_Header_Unique_Sequence_Number>3</Label_Header_Header_Unique_Sequence_Number>
</Label_Left>
<Detail_Line_Left>
<Line_Print_Description_1>RAK Fstzg Ardesia black gl.str</Line_Print_Description_1>
<Line_Print_Description_2>frb, R9, 30x60cm</Line_Print_Description_2>
</Detail_Line_Left>
<Label_Right>
<Label_Header_Header_Company>00500</Label_Header_Header_Company>
<Label_Header_Header_Unique_Sequence_Number>4</Label_Header_Header_Unique_Sequence_Number>
</Label_Right>
<Detail_Line_Right>
<Line_Print_Description_1>BAUMIT KlebeSpachtel 25kg</Line_Print_Description_1>
<Line_Print_Description_2></Line_Print_Description_2>
</Detail_Line_Right>
</Header_Label_Lower>
<Header_Label_Upper>
<Label_Left>
<Label_Header_Header_Company>1001</Label_Header_Header_Company>
<Label_Header_Header_Unique_Sequence_Number>1</Label_Header_Header_Unique_Sequence_Number>
</Label_Left>
<Detail_Line_Left>
<Line_Print_Description_1>PAR Wdfl Vivida bianco strukt.</Line_Print_Description_1>
<Line_Print_Description_2>30x60cm</Line_Print_Description_2>
</Detail_Line_Left>
<Detail_Line_Left>
<Line_Print_Description_1>PAR Wdfl Secret bianco 1.</Line_Print_Description_1>
<Line_Print_Description_2>29,5x59,5cm</Line_Print_Description_2>
</Detail_Line_Left>
<Label_Right>
<Label_Header_Header_Company>00500</Label_Header_Header_Company>
<Label_Header_Header_Unique_Sequence_Number>2</Label_Header_Header_Unique_Sequence_Number>
</Label_Right>
<Detail_Line_Right>
<Line_Print_Description_1>IRS Fstzg Porcelainw.Brownwood</Line_Print_Description_1>
<Line_Print_Description_2>frb. R9, 15x120cm</Line_Print_Description_2>
</Detail_Line_Right>
<Detail_Line_Right>
<Line_Print_Description_1>IRS Fstzg Porcelainw.Greywood</Line_Print_Description_1>
<Line_Print_Description_2>frb. R9, 15x120cm</Line_Print_Description_2>
</Detail_Line_Right>
<Detail_Line_Right>
<Line_Print_Description_1>IRS Fstzg Porcelainw.Blackwood</Line_Print_Description_1>
<Line_Print_Description_2>frb. R9, 15x120cm</Line_Print_Description_2>
</Detail_Line_Right>
</Header_Label_Upper>
<Header_Label_Lower>
<Label_Left>
<Label_Header_Header_Company>00500</Label_Header_Header_Company>
<Label_Header_Header_Unique_Sequence_Number>3</Label_Header_Header_Unique_Sequence_Number>
</Label_Left>
<Detail_Line>
<Line_Print_Description_1>RAK Fstzg Ardesia black gl.str</Line_Print_Description_1>
<Line_Print_Description_2>frb, R9, 30x60cm</Line_Print_Description_2>
</Detail_Line>
<Label_Right>
<Label_Header_Header_Company>00500</Label_Header_Header_Company>
<Label_Header_Header_Unique_Sequence_Number>4</Label_Header_Header_Unique_Sequence_Number>
</Label_Right>
<Detail_Line>
<Line_Print_Description_1>BAUMIT KlebeSpachtel 25kg</Line_Print_Description_1>
<Line_Print_Description_2></Line_Print_Description_2>
</Detail_Line>
</Header_Label_Lower>
</document>
Given your example XML, the following XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" indent="yes" standalone="no"/>
<xsl:strip-space elements="*"/>
<!-- The identity transform. -->
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<!-- Match the root node. -->
<xsl:template match="document">
<xsl:copy>
<!-- Restructure each subset of four Header_Label_Header elements. -->
<xsl:for-each select="*[position() mod 4 = 1]">
<xsl:call-template name="subset">
<xsl:with-param name="subset-nodes" select=". | following-sibling::*[position() < 4]"/>
</xsl:call-template>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template name="subset">
<xsl:param name="subset-nodes"/>
<!-- Select the first and third elements and give them appropriate upper/lower labels. -->
<xsl:for-each select="$subset-nodes[position() mod 2 = 1]">
<xsl:choose>
<xsl:when test="position() = 1">
<Header_Label_Upper>
<!-- Select this element and the one that follows it. -->
<xsl:apply-templates select=". | following-sibling::*[position() < 2]"/>
</Header_Label_Upper>
</xsl:when>
<xsl:otherwise>
<Header_Label_Lower>
<!-- Select this element and the one that follows it. -->
<xsl:apply-templates select=". | following-sibling::*[position() < 2]"/>
</Header_Label_Lower>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<!-- Match the Header_Label_Header elements and give them appropriate left/right labels. -->
<xsl:template match="*[contains(local-name(), 'Header_Label_Header_')]">
<xsl:choose>
<xsl:when test="position() = 1">
<Label_Left>
<xsl:apply-templates select="*[contains(local-name(), 'Label_Header_Header_')]"/>
</Label_Left>
<xsl:apply-templates select="Detail_Line" mode="Left"/>
</xsl:when>
<xsl:otherwise>
<Label_Right>
<xsl:apply-templates select="*[contains(local-name(), 'Label_Header_Header_')]"/>
</Label_Right>
<xsl:apply-templates select="Detail_Line" mode="Right"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="Detail_Line" mode="Left">
<Detail_Line_Left>
<xsl:apply-templates/>
</Detail_Line_Left>
</xsl:template>
<xsl:template match="Detail_Line" mode="Right">
<Detail_Line_Right>
<xsl:apply-templates/>
</Detail_Line_Right>
</xsl:template>
</xsl:stylesheet>
output the desired XML.
The template could probably be improved as there is a bit of duplicated code, but it does the job.

Crypto++ and Compressed EC keys

How can I generate compressed ECDSA keys in Crypto++?
AutoSeededRandomPool prng;
ECDSA<ECP, SHA1>::PrivateKey privateKey;
ECDSA<ECP, SHA1>::PublicKey publicKey;
privateKey.Initialize( prng, CryptoPP::ASN1::secp256r1());
const Integer& x1 = privateKey.GetPrivateExponent();
cout << "priv: " << std::hex << x1 << endl;
privateKey.MakePublicKey( publicKey );
const ECP::Point& q = publicKey.GetPublicElement();
const Integer& qx = q.x;
const Integer& qy = q.y;
cout << "pub x: " << std::hex << qx << endl;
cout << "pub y: " << std::hex << qy << endl;
This code generates a keypair and prints the X and Y components of the public key.
I need to know if there is a way to print the Y component of the compressed key, or if I need to generate it from the uncompressed y component. If I need to generate it, can someone link me to a good explanation of how to work with the Integer class?
How can I generate compressed ECDSA keys in CryptoPP?
You don't create a compressed key. You generate a public key, and then you compress it if that's what is required. From How to construct a public ECDSA key with point compression turned on? on the Crpyto++ user group:
ECDSA<ECP, SHA1>::Verifier verifier(...);
verifier.AccessKey().AccessGroupParameters().SetPointCompression(true);
In your case, it will be:
publicKey.AccessGroupParameters().SetPointCompression(true);
since verifier.AccessKey() returns the ECDSA public key.
I need to know if there is a way to print the Y component of the compressed key
Compression is a presentation format option or optimization. You can't print the Y component on a serialized key with compression because its not there (see the ASN.1 dumps below).
With compression on, the Y "shorthand" is going to be 1 or -1, depending on the sign of the component (the sign indicates what quadrant the point is in). The idea is someone sends you a {1,X} pair or {-1,X} pair and you can solve for Y because you know which quadrant it should be in. If Y is only allowed to be positive, you only need to serialize {X} (and not {-1,X} or {1,X}). (I did not dive into the books or standards, so there may be some errata here).
... or if I need to generate it from the uncompressed y component. If I need to generate it, can someone link me to a good explanation of how to work with the Integer class?
I have no idea what you're talking about at here. Point compression affects presentation. If you turn on point compression and fetch Y, you will still get Y out. You can't compute on a compressed point. You need the X and Y coordinates.
Add the following to your program:
publicKey.AccessGroupParameters().SetPointCompression(false);
ByteQueue q1;
publicKey.Save(q1);
cout << "Uncompressed size: " << dec << q1.MaxRetrievable() << endl;
publicKey.AccessGroupParameters().SetPointCompression(true);
ByteQueue q2;
publicKey.Save(q2);
cout << "Compressed size: " << dec << q2.MaxRetrievable() << endl;
Here's what I got for the output:
$ ./cryptopp-test.exe
priv: 4ce30d22d9593d9c7f4406eda1ce0740c7486106374d0abe7e352e1d5b1d5622h
pub x: 41a9bc936b6d1dd3a1ded997d7da08f1df990e9b50f9b58e9e4fd9319758ea34h
pub y: 4ad39ffb79c402063a99ecbc0cac8fde606db6764ace90933feee5f8d65937a2h
Uncompressed size: 311
Compressed size: 246
If you fetch Y after turning on point compression, you will still get 4ad39ffb79c402063a99ecbc0cac8fde606db6764ace90933feee5f8d65937a2h because compression affects presentation.
Now, add the following to dump the uncompressed and compressed key:
FileSink fs1("key-1.der", true);
q1.TransferTo(fs1);
FileSink fs2("key-2.der", true);
q2.TransferTo(fs2);
The keys are dumped in ASN.1's DER encoding and conform to Certicom's SEC 1: Elliptic Curve Cryptography (and to a lesser extent, ANSI 9.62 and RFC 5480, ECC SubjectPublicKeyInfo Format - see below on the Field Element's OCTET STRING vs BIT STRING).
You can run Peter Gutmann's dumpasn1 on them:
$ dumpasn1.exe key-1.der
0 307: SEQUENCE {
4 236: SEQUENCE {
7 7: OBJECT IDENTIFIER ecPublicKey (1 2 840 10045 2 1)
16 224: SEQUENCE {
19 1: INTEGER 1
22 44: SEQUENCE {
24 7: OBJECT IDENTIFIER prime-field (1 2 840 10045 1 1)
33 33: INTEGER
: 00 FF FF FF FF 00 00 00 01 00 00 00 00 00 00 00
: 00 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF
: FF
: }
68 68: SEQUENCE {
70 32: OCTET STRING
: FF FF FF FF 00 00 00 01 00 00 00 00 00 00 00 00
: 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FC
104 32: OCTET STRING
: 5A C6 35 D8 AA 3A 93 E7 B3 EB BD 55 76 98 86 BC
: 65 1D 06 B0 CC 53 B0 F6 3B CE 3C 3E 27 D2 60 4B
: }
138 65: OCTET STRING
: 04 6B 17 D1 F2 E1 2C 42 47 F8 BC E6 E5 63 A4 40
: F2 77 03 7D 81 2D EB 33 A0 F4 A1 39 45 D8 98 C2
: 96 4F E3 42 E2 FE 1A 7F 9B 8E E7 EB 4A 7C 0F 9E
: 16 2B CE 33 57 6B 31 5E CE CB B6 40 68 37 BF 51
: F5
205 33: INTEGER
: 00 FF FF FF FF 00 00 00 00 FF FF FF FF FF FF FF
: FF BC E6 FA AD A7 17 9E 84 F3 B9 CA C2 FC 63 25
: 51
240 1: INTEGER 1
: }
: }
243 66: BIT STRING
: 04 41 A9 BC 93 6B 6D 1D D3 A1 DE D9 97 D7 DA 08
: F1 DF 99 0E 9B 50 F9 B5 8E 9E 4F D9 31 97 58 EA
: 34 4A D3 9F FB 79 C4 02 06 3A 99 EC BC 0C AC 8F
: DE 60 6D B6 76 4A CE 90 93 3F EE E5 F8 D6 59 37
: A2
: }
$ dumpasn1.exe key-2.der
0 243: SEQUENCE {
3 204: SEQUENCE {
6 7: OBJECT IDENTIFIER ecPublicKey (1 2 840 10045 2 1)
15 192: SEQUENCE {
18 1: INTEGER 1
21 44: SEQUENCE {
23 7: OBJECT IDENTIFIER prime-field (1 2 840 10045 1 1)
32 33: INTEGER
: 00 FF FF FF FF 00 00 00 01 00 00 00 00 00 00 00
: 00 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF
: FF
: }
67 68: SEQUENCE {
69 32: OCTET STRING
: FF FF FF FF 00 00 00 01 00 00 00 00 00 00 00 00
: 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FC
103 32: OCTET STRING
: 5A C6 35 D8 AA 3A 93 E7 B3 EB BD 55 76 98 86 BC
: 65 1D 06 B0 CC 53 B0 F6 3B CE 3C 3E 27 D2 60 4B
: }
137 33: OCTET STRING
: 03 6B 17 D1 F2 E1 2C 42 47 F8 BC E6 E5 63 A4 40
: F2 77 03 7D 81 2D EB 33 A0 F4 A1 39 45 D8 98 C2
: 96
172 33: INTEGER
: 00 FF FF FF FF 00 00 00 00 FF FF FF FF FF FF FF
: FF BC E6 FA AD A7 17 9E 84 F3 B9 CA C2 FC 63 25
: 51
207 1: INTEGER 1
: }
: }
210 34: BIT STRING
: 02 41 A9 BC 93 6B 6D 1D D3 A1 DE D9 97 D7 DA 08
: F1 DF 99 0E 9B 50 F9 B5 8E 9E 4F D9 31 97 58 EA
: 34
: }
Notice the differences:
# key-1.der
243 66: BIT STRING
: 04 41 A9 BC 93 6B 6D 1D D3 A1 DE D9 97 D7 DA 08
: F1 DF 99 0E 9B 50 F9 B5 8E 9E 4F D9 31 97 58 EA
: 34 4A D3 9F FB 79 C4 02 06 3A 99 EC BC 0C AC 8F
: DE 60 6D B6 76 4A CE 90 93 3F EE E5 F8 D6 59 37
: A2
versus:
# key-2.der
210 34: BIT STRING
: 02 41 A9 BC 93 6B 6D 1D D3 A1 DE D9 97 D7 DA 08
: F1 DF 99 0E 9B 50 F9 B5 8E 9E 4F D9 31 97 58 EA
: 34
: }
The first has two Integers encoded, while the second has one Integer encoded. The common value is 41 A9 BC 93 ... 97 58 EA 34, and that's your pub x above. The missing string from key-2 is 4A D3 9F FB ... D6 59 37 A2, and that's the pub y above. For completeness, the values are encoded as either {X,Y} or {X}, and not ASN.1's encoding of integers.
The final difference is the first octet of the BIT STRING: 02 versus 04 (or 03). 04 indicates its an uncompressed point. From RFC 5480, Section 2.2:
The first octet of the OCTET STRING indicates whether the key is
compressed or uncompressed. The uncompressed form is indicated
by 0x04 and the compressed form is indicated by either 0x02 or
0x03 (see 2.3.3 in [SEC1]). The public key MUST be rejected if
any other value is included in the first octet.
And after looking at the standard and section 2.2, Crypto++ may have a bug: its writing a BIT STRING, but the standard is clearly discussing a OCTET STRING.
EDIT 1: It appears this is a Crypto++ bug under ANSI 9.62, too. Section 6.2, Syntax for Finite Field Elements and Elliptic Curve Points (p. 20)
A finite field element shall be represented by a value of type FieldElement:
FieldElement ::= OCTET STRING
The value of FieldElement shall be the octet string representation of a field
elementfollowing the conversion routine in Section 4.3.1.
An elliptic curve point shall be represented by a value of type ECPoint:
ECPoint ::= OCTET STRING
EDIT 2: Crypto++ is using the format specified by Certicom's SEC 1: Elliptic Curve Cryptography. Appendix C (page 77) states:
Finally, a specific field element is represented by the following type
FieldElement ::= OCTET STRING
whose value is the octet string obtained from the conversion routines
given in Section 2.3.5.