mirror of
				https://github.com/PurpleI2P/i2pd.git
				synced 2025-11-04 08:30:46 +00:00 
			
		
		
		
	base32 encode
This commit is contained in:
		
							parent
							
								
									aaa8e39d68
								
							
						
					
					
						commit
						90fe263124
					
				
					 2 changed files with 31 additions and 0 deletions
				
			
		
							
								
								
									
										30
									
								
								base64.cpp
									
										
									
									
									
								
							
							
						
						
									
										30
									
								
								base64.cpp
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -232,5 +232,35 @@ namespace data
 | 
			
		|||
		}
 | 
			
		||||
		return ret;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	size_t ByteStreamToBase32 (const uint8_t * inBuf, size_t len, char * outBuf, size_t outLen)
 | 
			
		||||
	{
 | 
			
		||||
		size_t ret = 0, pos = 1;
 | 
			
		||||
		int bits = 8, tmp = inBuf[0];
 | 
			
		||||
		while (ret < outLen && (bits > 0 || pos < len))
 | 
			
		||||
		{ 	
 | 
			
		||||
			if (bits < 5)
 | 
			
		||||
			{
 | 
			
		||||
				if (pos < len)
 | 
			
		||||
				{
 | 
			
		||||
					tmp <<= 8;
 | 
			
		||||
		      		tmp |= inBuf[pos] & 0xFF;
 | 
			
		||||
					pos++;
 | 
			
		||||
		      		bits += 8;
 | 
			
		||||
				}
 | 
			
		||||
				else // last byte
 | 
			
		||||
				{
 | 
			
		||||
					tmp <<= (5 - bits);
 | 
			
		||||
				  	bits = 5;
 | 
			
		||||
				}
 | 
			
		||||
			}	
 | 
			
		||||
		
 | 
			
		||||
			bits -= 5;
 | 
			
		||||
			int ind = (tmp >> bits) & 0x1F;
 | 
			
		||||
			outBuf[ret] = (ind < 26) ? (ind + 'a') : ((ind - 26) + '2');
 | 
			
		||||
			ret++;
 | 
			
		||||
		}
 | 
			
		||||
		return ret;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1
									
								
								base64.h
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								base64.h
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -14,6 +14,7 @@ namespace data
 | 
			
		|||
	const char * GetBase64SubstitutionTable ();	
 | 
			
		||||
	
 | 
			
		||||
	size_t Base32ToByteStream (const char * inBuf, size_t len, uint8_t * outBuf, size_t outLen);
 | 
			
		||||
	size_t ByteStreamToBase32 (const uint8_t * InBuf, size_t len, char * outBuf, size_t outLen);
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue