• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 845
  • Last Modified:

Batch File: Convert a text file

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
ReneGe
Asked:
ReneGe
  • 5
  • 2
2 Solutions
 
knightEknightCommented:
Please show us the progress you have made so far, and we can help you from there.
0
 
ReneGeAuthor Commented:
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
 
abbrightCommented:
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
ReneGeAuthor Commented:
@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
 
abbrightCommented:
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
 
ReneGeAuthor Commented:
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
 
ReneGeAuthor Commented:
This question is getting old.

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

Cheers,
Rene
0
 
ReneGeAuthor Commented:
Question was not answered.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now