I have a binary data as
00 10 11 01 10 11 11 01
I need to replace this data as if
00 = 001 = 110 or 11 = *
if i get a new data as below
0 * * 1 * * * 1
can you suggest any way to get back the binary data
00 10 11 01 10 11 11 01
encryption
00 10 11 01 10 11 11 01
00 = 001 = 110 or 11 = *
0 * * 1 * * * 1
00 10 11 01 10 11 11 01
%% Read txt file
% Reset all the variables
clear;clc;% Read the content of the text file into memory
content = fileread('Original_1.txt');% Declare desired string occurences (columns) to create the storage cell
% (initially with an unknown size) and store specified columns
desired_string = ["FOPT", "FGPT", "FWPT", "WOPR", "WWPR", "WOPT", "WWPT", "WGPT", "WGPR", "WBHP", "WGOR" ];% Create cell array to store the columns desired
count_string = count(content,desired_string );storage = cell(1,count_string);% Delete unnecessary strings and special characters for readibility (should
% be left with 130 characters "per line"-content variable in workspace is a
% character vector of size 1*154485). Warning: New line and carriage return
% characters also need to be deleted to get 130 characters "per line".
new_content = regexprep(content, '"SUMMARY\s.*$|"-.*$|SUMMARY\s.*$|^\s+|\n|\r', '', 'lineanchors', 'dotexceptnewline');% If first 13 characters containts the string 'DATE' insert '!' to beginning
% as a delimiter to separate into pages
search_string = {'"','DATE'};first_13 = new_content(1:13);if contains(first_13,search_string(1,1)) new_str = insertBefore(new_content, '"DATE', '!'); final_str = strsplit(new_str, '!');elseif contains(first_13, search_string(1,2)) new_str = insertBefore(new_content, 'DATE', '!'); final_str = strsplit(new_str, '!');end% Search for a specific string and read all the columns
pages = length(final_str);add = 13;count = 0;next_column = 0;% For loop for reading each page of the content
for ii = 2:pages % Convert cell into character vector
new_char_vec = char(final_str(1,ii)); % Length of each character vector in each cell
long = length(char(final_str(1,ii))); % Column number of each page!
row_no = long/130; % Read first 130 characters, 13 characters at a time 10 times and
% match the desired string
for i = 1:10 row = 1 + count; column = 13 + count; testing = new_char_vec(1, (row:column)); count = count + add; % if contains 'FOPT' %read all the columns related
if contains(testing,desired_string) % Move to next column of storage cell when string is found
next_column = next_column + 1; % Create cell array inside each column of storage cell array
% row_no varies
storage{1,next_column} = cell(row_no,1); % read_rows and read_columns are reset to row and column
% everytime the desired_string is found
read_rows = row; read_columns = column; % Store the the desired string column's first row
storage{1,next_column}{1,1} = new_char_vec(1, (read_rows:read_columns)); % Store each row of the desired string column (starting from 2nd row) in a for loop
for jj = 2:(row_no) read_rows = read_rows + 130; read_columns = read_columns + 130; storage{1,next_column}{jj,1} = new_char_vec(1, (read_rows:read_columns)); end end end % Reset count
count = 0;end% Clear all the unnecessary variables
clear add column content count count_string desired_string final_str first_13 i ii jj long new_char_vec new_content new_str next_column pages read_rows read_columns row row_no search_string testing
fid = fopen( 'c:\m\cssm\test4.txt' );rows = textscan( fid, '%s', 'Delimiter', '\n' );fclose( fid );rows = rows{:};str = 'RainflowCycleCounterHistogram'; % avoid magic number
len = length( str );is_counter = strncmp( str, rows, len ); counter_rows = rows( is_counter );%
str = 'RainflowCycleMeanBreakpoints'; len = length( str );is_mean = strncmp( str, rows, len ); mean_rows = rows( is_mean );%str = 'RainflowCycleRangeBreakpoints'; len = length( str );is_range = strncmp( str, rows, len ); range_rows = rows( is_range );%counter_matrix = nan( 10, 10 );for jj = 1 : length( counter_rows )%
cac = textscan( counter_rows{jj}, '%*s%d%d%f' ... , 'Delimiter' , ' []:' ... , 'MultipleDelimsAsOne', true ); %
counter_matrix( cac{1}+1, cac{2}+1 ) = cac{3}; % one based
endmean_vector = nan( 1, 10 );for jj = 1 : length( mean_rows )% cac = textscan( mean_rows{jj}, '%*s%d%f' ... , 'Delimiter' , ' []:' ... , 'MultipleDelimsAsOne', true ); % mean_vector( 1, cac{1}+1 ) = cac{2}; % one based endrange_vector = nan( 1, 10 );for jj = 1 : length( range_rows )% cac = textscan( range_rows{jj}, '%*s%d%f' ... , 'Delimiter' , ' []:' ... , 'MultipleDelimsAsOne', true ); % range_vector( 1, cac{1}+1 ) = cac{2}; % one based end
fid = fopen( 'c:\m\cssm\test4.txt' );rows = textscan( fid, '%s', 'Delimiter', '\n' );fclose( fid );rows = rows{:};str = 'RainflowCycleCounterHistogram'; % avoid magic numberlen = length( str );is_counter = strncmp( str, rows, len ); counter_rows = rows( is_counter );%str = 'RainflowCycleMeanBreakpoints'; len = length( str );is_mean = strncmp( str, rows, len ); mean_rows = rows( is_mean );%str = 'RainflowCycleRangeBreakpoints'; len = length( str );is_range = strncmp( str, rows, len ); range_rows = rows( is_range );%CRS = permute( char( counter_rows ), [2,1] );cac = textscan( CRS, '%*s%f%f%f' ... , 'Delimiter' , '[]: '... , 'MultipleDelimsAsOne' , true ... , 'CollectOutput' , true ); num = cac{1}; %
sz1 = min( num(:,1:2), [], 1 );sz2 = max( num(:,1:2), [], 1 );sz = sz2-sz1+[1,1];ix_linear = sub2ind( sz, num(:,1)+1, num(:,2)+1 ); % one based
counter_matrix( ix_linear ) = num(:,3); counter_matrix = reshape( counter_matrix, sz );MRS = permute( char( mean_rows ), [2,1] );cac = textscan( MRS, '%*s%f%f' ... , 'Delimiter' , '[]: '... , 'MultipleDelimsAsOne' , true ... , 'CollectOutput' , true ); num = cac{1}; % mean_vector( num(:,1)+1 ) = num(:,2); % one based
RRS = permute( char( range_rows ), [2,1] );cac = textscan( RRS, '%*s%f%f' ... , 'Delimiter' , ' []:'... , 'MultipleDelimsAsOne' , true ... , 'CollectOutput' , true ); % range_vector( num(:,1)+1 ) = num(:,2); % one based
>> S = cssm( 'c:\m\cssm\text4.txt' )S = RainflowCycleCounterHistogram: [10x10 double] RainflowCycleMeanBreakpoints: [-111 100 300 330 360 380 390 400 410 420] RainflowCycleRangeBreakpoints: [0 35 70 100 135 170 200 230 260 300] RainflowCycleReversalTolerance: 20 PowerCylinderTemperature: 0 PowerCylinderTemperatureHistogram: [1x12 double] PowerCylinderTemperatureHistogramBreakpoints: [0 150 175 200 220 250 300 320 350 370 400]>>
function S = cssm( filespec ) fid = fopen( filespec ); rows = textscan( fid, '%s', 'Delimiter', '\n' ); fclose( fid ); rows = strtrim( rows{:} ); type_list = { ... format keyword 'f1', 'RainflowCycleCounterHistogram' 'f2', 'RainflowCycleMeanBreakpoints' 'f2', 'RainflowCycleRangeBreakpoints' 'f3', 'RainflowCycleReversalTolerance' 'f3', 'PowerCylinderTemperature' 'f2', 'PowerCylinderTemperatureHistogram' 'f2', 'PowerCylinderTemperatureHistogramBreakpoints' }; for jj = 1 : size( type_list, 1 ) switch type_list{jj,1} case 'f1' S.(type_list{jj,2}) = f1( type_list{jj,2}, rows ); case 'f2' S.(type_list{jj,2}) = f2( type_list{jj,2}, rows ); case 'f3' S.(type_list{jj,2}) = f3( type_list{jj,2}, rows ); otherwise error( 'The format, "%s", is not yet implemented', type_list{jj,1} ) end endendfunction matrix = f1( keyword, rows ) ism = is_member( keyword, rows ); cur_rows = rows( ism ); % str = permute( char( cur_rows ), [2,1] ); cac = textscan( str, '%*s%f%f%f' ... , 'Delimiter' , '[]: '... , 'MultipleDelimsAsOne' , true ... , 'CollectOutput' , true ); num = cac{1}; % sz1 = min( num(:,1:2), [], 1 ); sz2 = max( num(:,1:2), [], 1 ); sz = sz2-sz1+[1,1]; ix_linear = sub2ind( sz, num(:,1)+1, num(:,2)+1 ); % one based matrix( ix_linear ) = num(:,3); matrix = reshape( matrix, sz );endfunction matrix = f2( keyword, rows ) ism = is_member( keyword, rows ); cur_rows = rows( ism ); % str = permute( char( cur_rows ), [2,1] ); cac = textscan( str, '%*s%f%f' ... , 'Delimiter' , '[]: '... , 'MultipleDelimsAsOne' , true ... , 'CollectOutput' , true ); num = cac{1}; % matrix( num(:,1)+1 ) = num(:,2); % one based endfunction matrix = f3( keyword, rows ) ism = is_member( keyword, rows ); cur_rows = rows( ism ); % str = permute( char( cur_rows ), [2,1] ); cac = textscan( str, '%*s%f', 'Delimiter',':' ); matrix = cac{:}; endfunction ism = is_member( keyword, rows ) % the keyword is followed by either ":" or "["
cac = regexp( rows, ['^',keyword,'(?=(:|\[))'], 'once' ); ism = not( cellfun( @isempty, cac ) );end
Best Answer