# Hamming Code Strategy for Medical Image Sharing
## 3 Hamming Codes
### Using (15,11) Hamming Code  
When using (15,11) Hamming code, the algorithms for shadow generation and original image reconstruction are similar to those in using (7,4) Hamming code. The difference is in the number of bits from the pixels of the original images selected for computing. Using (7,4) Hamming code we can select from the most significant bits, or from the least significant bits of a pixel, whereas we can only select either the most significant bits or the least significant bits of a pixel when using (15,11) Hamming code because we use at least 7 bits from a pixel in our algorithms. Algorithms of shadow generation and the recovery of original images are briefly described below. **Algorithm:** Shadows generation algorithm  
**Input:**\(P_{1}\) and \(P_{2}\)  
**Output:**\(P^{\prime}{}_{1}\) and \(P^{\prime}{}_{2}\)  
**Step 1. ** Assign \([d_{1}d_{2}d_{3}d_{4}d_{5}d_{6}d_{7}d_{8}d_{9}d_{10}d_{11}]\)\(=[i_{1,1}i_{1,2}i_{1,3}i_{1,4}i_{1,5}i_{1,6}i_{1,7}i_{1,8}i_{2,1}i_{2,2}i_{2,3}]\), and \([x_{1}x_{2}x_{3}x_{4}]\)\(=[i_{2,4}i_{2,5}i_{2,6}i_{2,7}]\). **Step 2. ** Use (15,11) Hamming code to compute \(c=d\)*\(G\)\(=[p_{1}p_{2}p_{3}p_{4}d_{1}d_{2}d_{3}d_{4}d_{5}d_{6}d_{7}d_{8}d_{9}d_{10}d_{11}]\). **Step 3. ** For the codeword \(c\), flip the bit at the position \((x_{4}\ x_{3}\ x_{2}\ x_{1})_{2}\) to output a new codeword \(c^{\prime}=[p^{\prime}{}_{1}\ p^{\prime}{}_{2}\ p^{\prime}{}_{3}\ p^{\prime}{}_{4}\ d^{ \prime}{}_{1}\ d^{\prime}{}_{2}\ d^{\prime}{}_{3}\ d^{\prime}{}_{4}\ d^{\prime}{}_{5}\ d^{\prime}{}_{6}\ d^{ \prime}{}_{7}\ d^{\prime}{}_{8}\ d^{\prime}{}_{9}\ d^{\prime}{}_{10}\ d^{\prime}{}_{11}]\). \(=[d^{\prime}{}_{9}\;d^{\prime}{}_{10}\;d^{\prime}{}_{11}\;p^{\prime}{}_{2}\;p^{ \prime}{}_{3}\;p^{\prime}{}_{4}\;i_{2,8}]\). **Note:** Similar to the algorithms using (7,4) Hamming code, the input pixels are taken alternatively from two original images. \(P_{1}\) is first taken from \(I_{1}\), then in the next round \(P_{1}\) is taken from \(I_{2}\); the same goes for \(P_{2}\). This ensures that the outputs are mixed up nicely to produce the shadows. **Algorithm:** Original image reconstruction algorithm  
**Input:**\(P^{\prime}{}_{1}\) and \(P^{\prime}{}_{2}\)  
**Output:**\(P_{1}\) and \(P_{2}\)  
**Step 1. ** Assign \([d^{\prime}{}_{1}\;d^{\prime}{}_{2}\;d^{\prime}{}_{3}\;d^{\prime}{}_{4}\;d^{ \prime}{}_{5}\;d^{\prime}{}_{6}\;d^{\prime}{}_{7}\;d^{\prime}{}_{8}\;d^{\prime}{ }_{9}\;d^{\prime}{}_{10}\;d^{\prime}{}_{11}]=[o_{1,1}\;o_{1,2}\;o_{1,3}\;o_{1,4} \;o_{1,5}\;o_{1,6}\;o_{1,7}\;o_{1,8}\;o_{2,1}\;o_{2,2}\)  
\(o_{2,3}]\) from all eight bits of \(P^{\prime}{}_{1}\) and the first 3 bits of \(P^{\prime}{}_{2}\), and \([p^{\prime}{}_{1}\;p^{\prime}{}_{2}\;p^{\prime}{}_{3}\;p^{\prime}{}_{4}]=[o_{2, 4}\;o_{2,5}\;o_{2,6}\;o_{2,7}]\). **Step 2. ** Construct the codeword \(c^{\prime}=[p^{\prime}{}_{1}\;p^{\prime}{}_{2}\;p^{\prime}{}_{3}\;p^{\prime}{ }_{4}\;d^{\prime}{}_{1}\;d^{\prime}{}_{2}\;d^{\prime}{}_{3}\;d^{\prime}{}_{4} \;d^{\prime}{}_{5}\;d^{\prime}{}_{6}\;d^{\prime}{}_{7}\;d^{\prime}{}_{8}\;d^{ \prime}{}_{9}\;d^{\prime}{}_{10}\;d^{\prime}{}_{11}]\). **Step 3. ** Compute the syndrome \(s=[s_{4}\;s_{3}\;s_{2}\;s_{1}]=c^{\prime}\;{}_{8}\;H^{\rm T}\). **Step 4. ** If s is not equal to \([0\;0\;0\;0]\), go to Step 5; or else, stop the algorithm and return \(P_{1}{=}P^{\prime}{}_{1}\) and \(P_{2}{=}P^{\prime}{}_{2}\). **Step 5. ** Find the position of \((s_{4}\;s_{3}\;s_{2}\;s_{1})\) in \(H^{\rm T}\), i.e., \((x^{\prime}{}_{4}\;x^{\prime}{}_{3}\;x^{\prime}{}_{2}\;x^{\prime}{}_{1})_{2}\) and then obtain the correct codeword \([p_{1}\;p_{2}\;p_{3}\;p_{4}\;d_{1}\;d_{2}\;d_{3}\;d_{4}\;d_{5}\;d_{6}\;d_{7}\;d _{8}\;d_{9}\;d_{10}\;d_{11}]\). **Step 6. ** Output the pixels for the original medical images.