RORUTL03 ;HOIFO/CRT,SG - ENCRYPTION/DECRYPTION ; 7/14/05 2:59pm
;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
;
Q
;
;***** DECRYPTS THE STRING
DECRYPT(S) ;
N ASSOCIX,ASSOCSTR,IDIX,IDSTR
S ASSOCIX=$A($E(S,$L(S)))-31,IDIX=$A($E(S))-31
S ASSOCSTR=$P($T(Z+ASSOCIX),";;",2,99)
S IDSTR=$P($T(Z+IDIX),";;",2,99)
Q $TR($E(S,2,$L(S)-1),ASSOCSTR,IDSTR)
;
;***** ENCRYPTS THE STRING
ENCRYPT(S) ;
N %,ASSOCIX,ASSOCSTR,IDIX,IDSTR
S ASSOCIX=$R(20)+1
F S IDIX=$R(20)+1 Q:ASSOCIX'=IDIX
S ASSOCSTR=$P($T(Z+ASSOCIX),";;",2,99)
S IDSTR=$P($T(Z+IDIX),";;",2,99)
Q $C(IDIX+31)_$TR(S,IDSTR,ASSOCSTR)_$C(ASSOCIX+31)
;
;***** RETURNS DEFAULT SITE FOR HL7 MESSAGES
SITE(CS) ;
N RORSITE,RORSTN S:$G(CS)="" CS="^"
S RORSITE=$$SITE^VASITE
I RORSITE<0 D Q ""
. D ERROR^RORERR(-56,,,,RORSITE,"$$SITE^VASITE")
S RORSTN=$E($P(RORSITE,"^",3),1,3)
Q RORSTN_CS_$P(RORSITE,"^",2)_CS_"99VA4"
;
;***** XOR ENCRYPTION (from ICR v2.1)
XOR(X) ;
N I,SUFFIX
;--- Separate digits and letters (the suffix)
I X'?1N.N D S SUFFIX=$E(X,I,99),X=$E(X,1,I-1)
. F I=1:1 Q:$E(X,I)'?1N
;--- Convert the numeric part to hexadecimal
S X=$$CNV^XLFUTL(X,16)
;--- Perform XOR of each hexadecimal digit with '1101' (0xD)
S X=$TR(X,"0123456789ABCDEF","DCFE98BA54761032")
;--- Pad with 0xD from the left so that the value will contain
; no less that 9 hexadecimal digits, convert numeric part
;--- back to decimal and append the suffix (if available)
Q $$DEC^XLFUT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D0c?)LN6OHV]lG:5y'$*>nd[(tb!#
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HRORUTL03 3764 printed Dec 13, 2024@01:43:57 Page 2
RORUTL03 ;HOIFO/CRT,SG - ENCRYPTION/DECRYPTION ; 7/14/05 2:59pm
+1 ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
+2 ;
+3 QUIT
+4 ;
+5 ;***** DECRYPTS THE STRING
DECRYPT(S) ;
+1 NEW ASSOCIX,ASSOCSTR,IDIX,IDSTR
+2 SET ASSOCIX=$ASCII($EXTRACT(S,$LENGTH(S)))-31
SET IDIX=$ASCII($EXTRACT(S))-31
+3 SET ASSOCSTR=$PIECE($TEXT(Z+ASSOCIX),";;",2,99)
+4 SET IDSTR=$PIECE($TEXT(Z+IDIX),";;",2,99)
+5 QUIT $TRANSLATE($EXTRACT(S,2,$LENGTH(S)-1),ASSOCSTR,IDSTR)
+6 ;
+7 ;***** ENCRYPTS THE STRING
ENCRYPT(S) ;
+1 NEW %,ASSOCIX,ASSOCSTR,IDIX,IDSTR
+2 SET ASSOCIX=$RANDOM(20)+1
+3 FOR
SET IDIX=$RANDOM(20)+1
if ASSOCIX'=IDIX
QUIT
+4 SET ASSOCSTR=$PIECE($TEXT(Z+ASSOCIX),";;",2,99)
+5 SET IDSTR=$PIECE($TEXT(Z+IDIX),";;",2,99)
+6 QUIT $CHAR(IDIX+31)_$TRANSLATE(S,IDSTR,ASSOCSTR)_$CHAR(ASSOCIX+31)
+7 ;
+8 ;***** RETURNS DEFAULT SITE FOR HL7 MESSAGES
SITE(CS) ;
+1 NEW RORSITE,RORSTN
if $GET(CS)=""
SET CS="^"
+2 SET RORSITE=$$SITE^VASITE
+3 IF RORSITE<0
Begin DoDot:1
+4 DO ERROR^RORERR(-56,,,,RORSITE,"$$SITE^VASITE")
End DoDot:1
QUIT ""
+5 SET RORSTN=$EXTRACT($PIECE(RORSITE,"^",3),1,3)
+6 QUIT RORSTN_CS_$PIECE(RORSITE,"^",2)_CS_"99VA4"
+7 ;
+8 ;***** XOR ENCRYPTION (from ICR v2.1)
XOR(X) ;
+1 NEW I,SUFFIX
+2 ;--- Separate digits and letters (the suffix)
+3 IF X'?1N.N
Begin DoDot:1
+4 FOR I=1:1
if $EXTRACT(X,I)'?1N
QUIT
End DoDot:1
SET SUFFIX=$EXTRACT(X,I,99)
SET X=$EXTRACT(X,1,I-1)
+5 ;--- Convert the numeric part to hexadecimal
+6 SET X=$$CNV^XLFUTL(X,16)
+7 ;--- Perform XOR of each hexadecimal digit with '1101' (0xD)
+8 SET X=$TRANSLATE(X,"0123456789ABCDEF","DCFE98BA54761032")
+9 ;--- Pad with 0xD from the left so that the value will contain
+10 ; no less that 9 hexadecimal digits, convert numeric part
+11 ;--- back to decimal and append the suffix (if available)
+12 QUIT $$DEC^XLFUTL($TRANSLATE($JUSTIFY(X,9)," ","D"),16)_$GET(SUFFIX)
+13 ;
+14 ;***** ENCODES THE SPECIAL CHARACTERS (&, <, ', and ")
+15 ;
+16 ; STR Source string
+17 ;
XMLENC(STR) ;
+1 NEW CH,I,IC
+2 FOR I=1:1:5
SET CH=$EXTRACT("&<""'>",I)
SET IC=1
Begin DoDot:1
+3 FOR
SET IC=$FIND(STR,CH,IC)
if IC'>0
QUIT
Begin DoDot:2
+4 SET $EXTRACT(STR,IC-1,IC-1)=$PIECE("&^<^"^'^>","^",I)
End DoDot:2
End DoDot:1
+5 QUIT STR
+6 ;
+7 ;***** ENCRYPTION/DECRYPTION TABLE
Z ;;
+1 ;;ko-ZJtdG)49K{nX1BS$vH<:Myf*>Ae0!jQW=;#PwsO`E'%+rmb[gpqN,l6/hFC@DcUa ]zR}"ViIxu?872.(TYL5_3
+2 ;;`R;M/9BqAF%tSs#Vh)dO1DZP>r *fX'u[.4KlY=-mg_ci802N7LTG<]!CWo:3?{v+,5Q}(@jaExn$pIyHwzU"k6Jeb
+3 ;;ZJk"WQmCn!Y,y@1d+8s?[lNMxgHE(t=uwX:qSL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