<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Roundtrip to Shanghai via Tokyo &#187; ooxml</title>
	<atom:link href="http://kohei.us/tag/ooxml/feed/" rel="self" type="application/rss+xml" />
	<link>http://kohei.us</link>
	<description>Kohei Yoshida&#039;s Webspace</description>
	<lastBuildDate>Tue, 22 May 2012 04:18:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Excel sheet protection password hash</title>
		<link>http://kohei.us/2008/01/18/excel-sheet-protection-password-hash/</link>
		<comments>http://kohei.us/2008/01/18/excel-sheet-protection-password-hash/#comments</comments>
		<pubDate>Fri, 18 Jan 2008 23:35:58 +0000</pubDate>
		<dc:creator>Kohei Yoshida</dc:creator>
				<category><![CDATA[]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[code snippet]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[ooxml]]></category>

		<guid isPermaLink="false">http://kohei.us/2008/01/18/excel-workbookworksheet-protection-password-hash/</guid>
		<description><![CDATA[When you protect either your workbook or one of your worksheets with a password in Excel, Excel internally generates a 16-bit hash of your password and stores it instead of the original password text. The hashing algorithm used for that &#8230; <a href="http://kohei.us/2008/01/18/excel-sheet-protection-password-hash/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When you protect either your workbook or one of your worksheets with a password in Excel, Excel internally generates a 16-bit hash of your password and stores it instead of the original password text.  The hashing algorithm used for that was previously unknown, but thanks to the infamous <a href="http://www.ecma-international.org/publications/standards/Ecma-376.htm">Office Open XML specification</a> it is now documented for the world to see (take a look at <em>Part 4, Section 3.3.1.81 &#8211; Sheet Protection Options</em> for the details).  Thankfully, the algorithm is identical for all recent versions of Excel including XP, 2003 and 2007, so you can simply reuse the documented algorithm for the older versions of Excel too.</p>
<p>But alas! the documented algorithm is incorrect; it does not produce correct hash values.  Being determined to find out the correct algorithm, however, I started to analyze the hashes that the documented algorithm produces, and compare them with the real hash values that Excel generates, in order to decipher the correct algorithm.</p>
<p>In the end, the documented algorithm was, although not accurate, pretty close enough that I was able to make a few changes and derive the algorithm that generates correct values.  The following code:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">typedef</span> <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">char</span> sal_uInt8<span style="color: #008080;">;</span>
<span style="color: #0000ff;">typedef</span> <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">short</span> sal_uInt16<span style="color: #008080;">;</span>
&nbsp;
sal_uInt16 getPasswordHash<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> szPassword<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    sal_uInt16 cchPassword <span style="color: #000080;">=</span> <span style="color: #0000dd;">strlen</span><span style="color: #008000;">&#40;</span>szPassword<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    sal_uInt16 wPasswordHash <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span>cchPassword<span style="color: #008000;">&#41;</span>
        <span style="color: #0000ff;">return</span> wPasswordHash<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> pch <span style="color: #000080;">=</span> <span style="color: #000040;">&amp;</span>szPassword<span style="color: #008000;">&#91;</span>cchPassword<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span>pch<span style="color: #000040;">--</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> szPassword<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        wPasswordHash <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>wPasswordHash <span style="color: #000080;">&gt;&gt;</span> <span style="color: #0000dd;">14</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span> <span style="color: #208080;">0x01</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">|</span> 
                        <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>wPasswordHash <span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span> <span style="color: #208080;">0x7fff</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        wPasswordHash <span style="color: #000040;">^</span><span style="color: #000080;">=</span> <span style="color: #000040;">*</span>pch<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    wPasswordHash <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>wPasswordHash <span style="color: #000080;">&gt;&gt;</span> <span style="color: #0000dd;">14</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span> <span style="color: #208080;">0x01</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">|</span> 
                    <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>wPasswordHash <span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span> <span style="color: #208080;">0x7fff</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    wPasswordHash <span style="color: #000040;">^</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #208080;">0x8000</span> <span style="color: #000040;">|</span> <span style="color: #008000;">&#40;</span><span style="color: #FF0000;">'N'</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000dd;">8</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">|</span> <span style="color: #FF0000;">'K'</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    wPasswordHash <span style="color: #000040;">^</span><span style="color: #000080;">=</span> cchPassword<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> wPasswordHash<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> argc, <span style="color: #0000ff;">char</span><span style="color: #000040;">**</span> argv<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>argc <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span>
        <span style="color: #0000dd;">exit</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;input password = %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, argv<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    sal_uInt16 hash <span style="color: #000080;">=</span> getPasswordHash<span style="color: #008000;">&#40;</span>argv<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;hash = %4.4X<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, hash<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>produces the right hash value from an arbitrary password.  One caveat: this algorithm takes an 8-bit char array, so if the input value consists of 16-bit unicode characters, it needs to be first converted into 8-bit character array.  The conversion algorithm is also documented in the OOXML specification.  I have not tested it yet, but I hope that algorithm is correct. ;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://kohei.us/2008/01/18/excel-sheet-protection-password-hash/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Importing Excel 2007 files</title>
		<link>http://kohei.us/2007/06/20/importing-excel-2007-files/</link>
		<comments>http://kohei.us/2007/06/20/importing-excel-2007-files/#comments</comments>
		<pubDate>Wed, 20 Jun 2007 04:00:10 +0000</pubDate>
		<dc:creator>Kohei Yoshida</dc:creator>
				<category><![CDATA[]]></category>
		<category><![CDATA[calc]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[ooxml]]></category>
		<category><![CDATA[openoffice.org]]></category>

		<guid isPermaLink="false">http://blog.kohei.us/2007/06/20/importing-excel-2007-files/</guid>
		<description><![CDATA[The Excel 2007 filter for Calc is still on its way, but perhaps now is a good time to show the progress of this new Excel 2007 import filter work by Daniel Rentz and myself. Here is a screenshot of &#8230; <a href="http://kohei.us/2007/06/20/importing-excel-2007-files/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The Excel 2007 filter for Calc is still on its way, but perhaps now is a good time to show the progress of this new Excel 2007 import filter work by Daniel Rentz and myself.</p>
<p>Here is a screenshot of a file created by Excel 2007 (left), and one for the same file opened in Calc (right).</p>
<p align="center"><a href="http://blog.kohei.us/wp-content/uploads/2007/06/xlsx-shot-win.png" title="Excel 2007 screenshot"><img src="http://blog.kohei.us/wp-content/uploads/2007/06/xlsx-shot-win.thumbnail.png" alt="Excel 2007 screenshot" /></a> <a href="http://blog.kohei.us/wp-content/uploads/2007/06/xlsx-shot-calc.png" title="Excel 2007 file opened in Calc"><img src="http://blog.kohei.us/wp-content/uploads/2007/06/xlsx-shot-calc.thumbnail.png" alt="Excel 2007 file opened in Calc" /></a></p>
<p>There are still a lot to be done, however.  Formula import is still to be completed, which blocks other features that rely on the formula parser.  Charts, text boxes, and other graphic objects are still not imported yet.  There is also <a href="http://www.openoffice.org/issues/show_bug.cgi?id=78673">a performance issue of a large xlsx file import</a>, which needs to be addressed at some point.</p>
<p>But all in all, things are coming along very nicely.</p>
]]></content:encoded>
			<wfw:commentRss>http://kohei.us/2007/06/20/importing-excel-2007-files/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

