title: Convert OctalString (OS2IP) to Integer and viceversa (Integer to Octal String I2OSP) Objective-C
body: <p>I'm new in Objective-C and I'm having a few problems developing my code.</p>
  
  <p>I'm implementing RSA algorithm in Objective-C following this paper: <a href="http://www.inf.pucrs.br/~calazans/graduate/TPVLSI_I/RSA-oaep_spec.pdf" rel="nofollow">http://www.inf.pucrs.br/~calazans/graduate/TPVLSI_I/RSA-oaep_spec.pdf</a></p>
  
  <p>At this moment I'm trying to convert a non-negative integer into octet String (I2OSP) and its complementary operation, a octet String into a Integer (OS2IP).</p>
  
  <p>I've been able to get a kind of ItOSP function, but it hasn't the correct behaviour. This is what I have right now:</p>
  
  <pre><code>-(void) ItoOSP:(int) i buffer:(char []) buffer{
      OSStatus status = errSecSuccess;
      if(i&gt;=256){
          status=errSecParam;
          NSLog(@"Integer too long");
      }
  
      buffer[0] = (unsigned char)((i &gt;&gt; 24) &amp; 255);
      buffer[1] = (unsigned char)((i &gt;&gt; 16) &amp; 255);
      buffer[2] = (unsigned char)((i &gt;&gt; 8)) &amp; 255;
      buffer[3] = (unsigned char)(i &amp; 255);
  }
  </code></pre>
  
  <p>Could you provide me any hint to help me to achieve it please?</p>
  
  <p>I'm stuck in this hole and I can't move with the algorithm without it.</p>
  
  <p>Thanks in advance for your help!</p>
  
  <p>EDIT:</p>
  
  <p>The input and output of the methods are :</p>
  
  <p>OS2IP(X)
  Input: X octet string to be converted
  Output: x corresponding nonnegative integer</p>
  
  <p>I2OSP(x, l)
  Input: x nonnegative integer to be converted
  l intended length of the resulting octet string
  Output: X corresponding octet string of length l</p>
  
  <p>In the paper I've mentioned it appears the pseudo code to implement both of them, but as I said I'm rookie programming in objective-c (and C) and I'm not able to develop it. </p>