?
Solved

Batch File: Convert a text file

Posted on 2011-04-21
8
Medium Priority
?
835 Views
Last Modified: 2012-05-11
Hi there,

I need a batch file that will encrypt a text file by converting it's caracters to their ISO-8859-1 Hex value, and another one to convert them back to their ASCII value.

Please cover all of the ISO-8859-1 spectrum.

http://web.mit.edu/kenta/www/two/iso8859_files/fnt-mswin.gif

Thanks for your help,
Rene
0
Comment
Question by:ReneGe
  • 5
  • 2
8 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 500 total points
ID: 35446020
Please show us the progress you have made so far, and we can help you from there.
0
 
LVL 10

Author Comment

by:ReneGe
ID: 35446033
I actually don't know how to handle this. So I currently don't have any progress.

I was hoping that someone more experienced than me would allready have something done, or willing to the challange.

Thanks and cheers,
Rene
0
 
LVL 10

Assisted Solution

by:abbright
abbright earned 500 total points
ID: 35446762
Here is a website which might do what you want: http://www.mikezilla.com/exp0012.html. You may want to check the source code of the page to see how it works (in Internet Explorer select page => source code)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

by:ReneGe
ID: 35448140
@abbright

They use java script functions that does it all:
function convertToUnicode(source)
function convertToHex(num)
nction convertToASCII()

These functions does not exist in batch files.

Thanks for trying,
Rene
0
 
LVL 10

Expert Comment

by:abbright
ID: 35450418
I doubt this is easily possible using batch-language only. I think it will be easier to take an ordinary programming language like javascript / jscript, compile it and call the resulting program from within your batch file, therefore the example I sent you.
Another option would be to use powershell: Here's an example how to convert a string using powershell: http://learningpcs.blogspot.com/2009/07/powershell-string-to-hex-or-whatever.html
Hope that helps.
0
 
LVL 10

Author Comment

by:ReneGe
ID: 35470683
Here is what I've done so far.

My next challanges are:
-Encrease the :ConvertToNumber range of characters by adding Multiple FOR loops
-Split the %FileNum% by series of 20 set of numbers per line.
-Make the script sharper and cleaner
-Do a script to decode %FileNum% back to text (I could create a new question for this one)

 
@ECHO OFF

SETLOCAL enabledelayedexpansion

SET File=%~n0.txt
SET FileNum=%~n0_num.txt

IF EXIST %FileNum% DEL %FileNum%

REM SET COUNT TO POINT TO THE FIRST CHARACTER
	SET Count=0
	SET str=
	SET Line=

REM CREATING THE TEXT FILE
	ECHO THIS IS A TEST>%File%
	ECHO TEST>>%File%

REM CONVERTING THE TEXT FILE TO NUMBER
	FOR /F "usebackq delims=" %%A IN ("%File%") DO CALL :IsolateStr "%%A"

ECHO %Line%>%FileNum%
ECHO.
PAUSE
EXIT

:IsolateStr
SET Str=%~1
SET str=!str:~%Count%,1!

IF "!Str!" == "" (
	REM 888 REPRESENTS CRLF
	SET Line=%Line%888
	SET Count=0
	SET Str=
	EXIT /b
)
CALL :ConvertToNumber
SET /a Count+=1
GOTO IsolateStr


:ConvertToNumber

SET Str=%Str: =SPACE%

FOR %%A IN (SPACE:100,A:101,B:102,C:103,D:104,E:105,F:106,G:107,H:108,I:109,J:110,K:111,L:112,M:113,N:114,O:115,P:116,Q:117,R:118,S:119,T:120,U:121,V:122,W:123,X:124,Y:125,Z:126) DO (
	FOR /F "tokens=1,2 delims=:" %%B IN ("%%A") DO IF [%%~B] == [%Str%] SET Line=!Line!%%C
)

EXIT /b

REM TO BE ADDED
REM a:201,b:202,c:203,d:204,e:205,f:206,g:207,h:208,i:209,j:210,k:211,l:212,m:213,n:214,o:215,p:216,q:217,r:218,s:219,t:220,u:221,v:222,w:223,x:224,y:225,z:226
REM 1:301,2:302,3:303,4:304,5:305,6:306,7:307,8:308,9:309,0:310

Open in new window

0
 
LVL 10

Author Comment

by:ReneGe
ID: 35471628
This question is getting old.

I'll split the points and create a new one.

Cheers,
Rene
0
 
LVL 10

Author Closing Comment

by:ReneGe
ID: 35471630
Question was not answered.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ransomware - Defeated! Client opened the wrong email and was attacked by Ransomware. I was able to use file recovery utilities to find shadow copies of the encrypted files and make a complete recovery.
When you put your credit card number into a website for an online transaction, surely you know to look for signs of a secure website such as the padlock icon in the web browser or the green address bar.  This is one way to protect yourself from oth…
Simple Linear Regression
Introduction to Processes
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question