A. Here is the code for SQL 6.5

/************************************************/
/* REVISED REC'D 5/21/98 */
/* sp_decrypt_object Tom Sager 01/26/98 */
/* */
/* Decrypts objects (views, procedures & trigs) */
/* created with the WITH ENCRYPTION option. */
/* */
/* Uses the encrypt() built-in function to find */
/* a plaintext string that encrypts to the same */
/* value as stored in the text column of the */
/* syscomments table. */
/* */
/************************************************/
CREATE proc sp_decrypt_object
(@objname VARCHAR(30))
WITH ENCRYPTION
AS

SET NOCOUNT ON

DECLARE @errmsg VARCHAR(80)
DECLARE @encrtext VARCHAR(255)
DECLARE @decrtext VARCHAR(255)
DECLARE @testtext VARCHAR(255)
DECLARE @printline VARCHAR(255)
DECLARE @textlen INT
DECLARE @lup INT
DECLARE @MATCH CHAR(1)
DECLARE @testchar SMALLINT
DECLARE @begblk SMALLINT
DECLARE @endblk SMALLINT

IF (SELECT COUNT(*)
FROM sysobjects
WHERE name = @objname) = 0
BEGIN
SELECT @errmsg = 'Object '
+@objname
+' not found in database '
+DB_NAME()
print @errmsg
RETURN 1
END

IF (SELECT COUNT(*) FROM sysobjects t1,
syscomments t2
WHERE t1.name = @objname
AND t1.id = t2.id
AND t2.texttype & 4 != 0) = 0
BEGIN
SELECT @errmsg = 'Object '
+@objname
+' is not encrypted in database '
+DB_NAME()
print @errmsg
RETURN 1
END

DECLARE comments_cursor CURSOR FOR
SELECT t1.text
FROM syscomments t1,
sysobjects t2
WHERE t1.id = t2.id
AND t2.name = @objname
ORDER BY t1.colid

OPEN comments_cursor

FETCH NEXT FROM comments_cursor
INTO @encrtext

WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
SELECT @decrtext = REPLICATE(' ', 255)
SELECT @textlen = DATALENGTH(@encrtext)
SELECT @lup = 1
SELECT @MATCH = 'n'
while (@lup <= @textlen)
BEGIN
SELECT @testchar = 0
SELECT @MATCH = 'n'
while (@MATCH = 'n')
BEGIN
SELECT @decrtext =
STUFF(@decrtext,@lup,1,CHAR(@testchar))
SELECT @testtext = encrypt(@decrtext)
IF ASCII(SUBSTRING(@testtext,@lup,1)) =
ASCII(SUBSTRING(@encrtext,@lup,1))
BEGIN
SELECT @MATCH = 'y'
END
SELECT @testchar = @testchar + 1
IF (@testchar > 255)
BEGIN
print 'Error...no match found'
RETURN 1
END
END
SELECT @lup = @lup + 1
END
SELECT @begblk = 1
SELECT @endblk = 1
while (@endblk <= @textlen)
BEGIN
IF (SUBSTRING(@decrtext,@endblk,1) = 0x0a)
BEGIN
SELECT @printline = @printline +
SUBSTRING(@decrtext
,@begblk
,@endblk-@begblk+1)
print @printline
SELECT @begblk = @endblk + 1
SELECT @endblk = @begblk
SELECT @printline = NULL
END
SELECT @endblk = @endblk + 1
END
SELECT @printline = @printline +
SUBSTRING(@decrtext
,@begblk
,@endblk-@begblk+1)
END
FETCH NEXT FROM comments_cursor INTO @encrtext
END
print @printline
CLOSE comments_cursor

DEALLOCATE comments_cursor
GO