Sponsored Content
Full Discussion: Reading binary content
Operating Systems Solaris Reading binary content Post 302958218 by wisecracker on Tuesday 20th of October 2015 09:12:30 AM
Old 10-20-2015
Hi jlliagre...
OK, using shell and od only in OSX 10.7.5 default terminal limited to 32 bytes for this basic DEMO. It can easily be enhanced upon...
(Both hexdump and od are used in AudioScope.sh as CygWin does not have hexdump.)
Code:
#!/bin/sh
# bin.sh
dd if=/dev/urandom of=/tmp/binary bs=32 count=1
for subscript in {0..31}
do
	num=`od -An -N1 -j$subscript -tu /tmp/binary`
	echo "Decimal number ="$num"..."
	echo "ibase=10; obase=2; $num" | bc
done

Results:-
Code:
Last login: Tue Oct 20 14:00:40 on ttys000
AMIGA:barrywalker~> cd Desktop/Code/Shell
AMIGA:barrywalker~/Desktop/Code/Shell> ./bin.sh
1+0 records in
1+0 records out
32 bytes transferred in 0.000031 secs (1032444 bytes/sec)
Decimal number = 48 ...
110000
Decimal number = 82 ...
1010010
Decimal number = 118 ...
1110110
Decimal number = 152 ...
10011000
Decimal number = 42 ...
101010
Decimal number = 11 ...
1011
Decimal number = 185 ...
10111001
Decimal number = 185 ...
10111001
Decimal number = 101 ...
1100101
Decimal number = 238 ...
11101110
Decimal number = 6 ...
110
Decimal number = 11 ...
1011
Decimal number = 87 ...
1010111
Decimal number = 62 ...
111110
Decimal number = 12 ...
1100
Decimal number = 94 ...
1011110
Decimal number = 1 ...
1
Decimal number = 142 ...
10001110
Decimal number = 233 ...
11101001
Decimal number = 102 ...
1100110
Decimal number = 57 ...
111001
Decimal number = 39 ...
100111
Decimal number = 149 ...
10010101
Decimal number = 134 ...
10000110
Decimal number = 46 ...
101110
Decimal number = 94 ...
1011110
Decimal number = 238 ...
11101110
Decimal number = 200 ...
11001000
Decimal number = 111 ...
1101111
Decimal number = 38 ...
100110
Decimal number = 191 ...
10111111
Decimal number = 248 ...
11111000
AMIGA:barrywalker~/Desktop/Code/Shell>

 

10 More Discussions You Might Find Interesting

1. Programming

Reading from a binary file

I'm having trouble with reading information back into a program from a binary file. when i try to display the contents of the file i get a Memory fault(coredump). would anyone be able to assist? this is my fread line fread(&file_data,sizeof(struct book_type),1,fileSave); ive also tried it without... (3 Replies)
Discussion started by: primal
3 Replies

2. Shell Programming and Scripting

Reading Numerical Binary Data using KSH

Hi, I've searched and couldn't find anyone else with this problem. Is there anyway (preferably using ksh - but other script languages would do) that I can read in binary float data into a text file. The data (arrays from various stages of radar processing) comes in various formats, but mainly... (3 Replies)
Discussion started by: Jonny2Vests
3 Replies

3. Programming

Reading a binary file in text or ASCII format

Hi All, Please suggest me how to read a binary file in text or ASCII format. thanks Nagendra (3 Replies)
Discussion started by: Nagendra
3 Replies

4. Shell Programming and Scripting

Problem in reading a file content

Hi, I am reading a file line by line using read line function of while loop. Each line contains 4 fields. I want to take these 4 values in 4 variables in each iteration so that i can use them in my script. The issue here is that my awk command is returning awkward results - Here is a sample line... (8 Replies)
Discussion started by: garman
8 Replies

5. Shell Programming and Scripting

Reading content of a variable to create a new one?

Hello. I've written up a script, that populates a variable with a list of tapes returned from my library. For example: 701940L3,701941L3,701942L3,701943L3,701944L3,701945L3,701946L3,701947L3,701948L3 So now, the variable "TAPELIST" contains those numbers, delimited by commas. I'd like to... (6 Replies)
Discussion started by: Stephan
6 Replies

6. Programming

reading binary files

#include <stdio.h> /* typedef struct { char name; int number; float balance; } acct_info_t; */ int main() { FILE *fptr; fptr = fopen("acct_info", "r"); int magic = 5; fseek(fptr,3,SEEK_SET); fread(&magic,sizeof(int),1,fptr);... (7 Replies)
Discussion started by: robin_simple
7 Replies

7. Programming

help with reading a binary file and fseek

this is my code and no matter what record number the user enters i cant get any of the records fields to read into the structure acct. What am i doing wrong? #include <stdio.h> typedef struct { char name; int number; float balance; } acct_info_t; int main (int... (0 Replies)
Discussion started by: bjhum33
0 Replies

8. Shell Programming and Scripting

Trouble reading content of file from a variable

Hi , i have a parameter which has path of a file. Now i need to have another parameter with the content of that file. I tried the belwo script , can any one please help. I dont want to use cat command to read. Can we do it with out using cat command. while read line do... (9 Replies)
Discussion started by: Ravindra Swan
9 Replies

9. Programming

How to replicate Ruby´s binary file reading with Java?

Hello to all guys, Maybe some expert could help me. I have a working ruby script shown below that reads a big binary file (more than 2GB). The chunks of data I want to analyze is separated by the sequence FF47 withing the binary. So, in the ruby script is defined as "line separator" =... (10 Replies)
Discussion started by: Ophiuchus
10 Replies

10. Programming

Reading flat file content

is there any unix tools that can read the text files like through SQL queries? (ie in Hadoop, Impala DB support flat file query) (1 Reply)
Discussion started by: omykarshan
1 Replies
MODULI(5)						      BSD File Formats Manual							 MODULI(5)

NAME
moduli -- Diffie-Hellman moduli DESCRIPTION
The /etc/moduli file contains prime numbers and generators for use by sshd(8) in the Diffie-Hellman Group Exchange key exchange method. New moduli may be generated with ssh-keygen(1) using a two-step process. An initial candidate generation pass, using ssh-keygen -G, calcu- lates numbers that are likely to be useful. A second primality testing pass, using ssh-keygen -T, provides a high degree of assurance that the numbers are prime and are safe for use in Diffie-Hellman operations by sshd(8). This moduli format is used as the output from each pass. The file consists of newline-separated records, one per modulus, containing seven space-separated fields. These fields are as follows: timestamp The time that the modulus was last processed as YYYYMMDDHHMMSS. type Decimal number specifying the internal structure of the prime modulus. Supported types are: 0 Unknown, not tested. 2 "Safe" prime; (p-1)/2 is also prime. 4 Sophie Germain; 2p+1 is also prime. Moduli candidates initially produced by ssh-keygen(1) are Sophie Germain primes (type 4). Further primality testing with ssh-keygen(1) produces safe prime moduli (type 2) that are ready for use in sshd(8). Other types are not used by OpenSSH. tests Decimal number indicating the type of primality tests that the number has been subjected to represented as a bitmask of the following values: 0x00 Not tested. 0x01 Composite number - not prime. 0x02 Sieve of Eratosthenes. 0x04 Probabilistic Miller-Rabin primality tests. The ssh-keygen(1) moduli candidate generation uses the Sieve of Eratosthenes (flag 0x02). Subsequent ssh-keygen(1) pri- mality tests are Miller-Rabin tests (flag 0x04). trials Decimal number indicating the number of primality trials that have been performed on the modulus. size Decimal number indicating the size of the prime in bits. generator The recommended generator for use with this modulus (hexadecimal). modulus The modulus itself in hexadecimal. When performing Diffie-Hellman Group Exchange, sshd(8) first estimates the size of the modulus required to produce enough Diffie-Hellman out- put to sufficiently key the selected symmetric cipher. sshd(8) then randomly selects a modulus from /etc/moduli that best meets the size requirement. SEE ALSO
ssh-keygen(1), sshd(8) STANDARDS
M. Friedl, N. Provos, and W. Simpson, Diffie-Hellman Group Exchange for the Secure Shell (SSH) Transport Layer Protocol, RFC 4419, March 2006 2006. BSD
September 26, 2012 BSD
All times are GMT -4. The time now is 02:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy